How to use shp2pgsql - postgis

My question should be very simple to answer for anyone not being a self-taught newbie like me...
On this page is a cheatsheet concerning a function to be used in GIS/DB environnement : http://www.bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqg
I would like to create a script allowing users to just have to click on it to launch the process, given the proper datas. But I don't understand how to use this. It obviously doesn't work in a Python console, nor directly in the windows console. How is it supposed to work ? What language is this ?
Thanks

shp2pgsql is indeed a command line tool. It comes with your PostgreSQL/PostGIS installation (usually) and, if not accessible via PATH-variable, can (usually) be run from within the /bin-folder in your PostgreSQL-Installation. You can also always 'make' the programm from source in any location yourself, if needed.
EDIT:
One way to set up a script (independent of whether you use it within qgis own python environment or not) would be to use Pythons subprocess (or os.system) module (check related question here) to write to shell and execute shp2pgsql.
A slightly more sophisitcated solution to (batch) insert (multiple) shapefiles via script could be to implement ogr2ogr via gdal/ogr module within python (check this blog). That, however, would require a working installation of the gdal core library, and the respective Python bindings (at least to use outside of QGIS Python environment, where it is pre-installed AFAIK), which can be tiresome at times. Once installed correctly, it offers a powerful (I dare say almighty) toolset for geodata management and manipulation via Python, though.
Apart from that, the blog link I provided also states the implementation of a batch insert script/tool (which operates ogr2ogr) in qgis 2.8 toolbox...maybe that can help you, either with your work directly or (via sourcecode) to point you in the direction of creating your own tool.

Related

Apple automator save as ### filename + extension selection

I'm trying to get some automator script going but I have no clue how to achieve it. It's like this:
in Processing I exported a batch of 1850 SVG's. These SVG's now have to be opened in an application called Cenon. This application can save SVG's as .hpgl files.
It's no problem to open a file in a specific application like Cenon when it's added to a folder. That works fine.
But how do I save this file in a specific extension like .hpgl and create a variable name? Because Cenon always opens a file with the name 'UNTITLED'.
So I need to do:
automatically open file one by one in Cenon
save file as .hpgl file
save file with variable name like (0001, 0002, 0003, 0004, 0005, etc.)
I hope someone can help me!!
Thanks in advance,
Fons.
First of all, let me make a distinction between two related technologies:
AppleEvents which are messages that can be used for different applications to communicate with each other, asking each other to do tasks.
AppleScript which is one kind of scripting language that can send and receive AppleEvents to and from Mac applications.
You can't use AppleEvents with Cenon but you still may be able to use AppleScript with Cenon. I know that you can't use AppleEvents with Cenon because I downloaded Cenon version 4.0.1 from the web and I tried to open up it's AppleEvent dictionary with the "AppleScript Editor.app" application that comes with OS X.
So, AppleEvents are out. This means the "tell" command in AppleScript can't tell the Cenon.app to do anything with AppleEvents, but you may still be able to use AppleScript.
AppleScript can be used by simulating user menu-selections and key strokes instead of using AppleEvents. Using AppleEvents would be better, but sometimes, using AppleScript, you have to go through the user interface.
An alternative to resorting to using AppleScript to simulate the user-interface (UI) would be to use a shell-command. It just seems to me that this would be a better solution, but you would have to find a Unix shell command that was compiled for Mac that would convert from .svg to .hpgl
If you really want to use AppleScript and Cenon.app, here is a link to study about using AppleScript going through the UI of an app:
http://www.macosxautomation.com/applescript/uiscripting/
AppleScript was originally designed to be a scripting language to take some of the functionality with application A, and then take some of the functionality of application B, etc, and glue it together with a little logic from AppleScript and empower the user to more easily automate their tasks.
AppleScript was designed to be an alternate user-interface, going through AppleEvents, but AppleEvents are not as widely supported as they could be by applications, so this kludgy solution of having AppleScript go through the GUI is commonly done.
Again, I think that a shell script would be a better solution for this problem and you could call is "solution.command" or you could embed the shell script into an Automator Workflow saved as an Application or embed the shell script within an AppleScript saved as an application. Either one work work.

How to run matlab script on server? or Is there an online matlab interpreter?

I have a matlab script Temp_script.m (say) which,I want to execute on remote
server.
The server(remote) that I am using is free online hosting which gives me 1.5GB storage.
Since the server is remote one, I have no access to it, to install matlab software or runtime environment.
locally I can run the matlab script on my server.Obviously because I have matlab installed on my system.
My question "Is there a method to run the script online.? or Is there
any online interpreter for matlab?"
Thanking in advance
-Ryaan Dias
You can compile your project using deploytool.
This will give you several options, you can make a dll and probably even an exe.
However, the program is not going to run itself, so if you want it to run automatically on the server you need to have a framework there. Example could be .net but i guess there are easier ones.
AFAIK there isn't a web interface for Matlab, and I doubt that the Matlab license would cover such a use case. However, there you could always try to use the open-source equivalent Octave . Octave can execute Matlab code with only minor modifications.
A quick google search for Octave Web Server yielded many results. This was the first hit:http://knn.mimuw.edu.pl/weboctave-project/

Execute a program with a custom .ini path

I make a fair amount portable Apps for personal use and they work perfectly for the most part. I do, however, find it quite frustrating that if I run them on another computer none of my preferences are retained, as a program always looks in appData for the configuration files (which obviously don't exist on another system), so I'm wondering whether there is some kind of command line to launch an .exe with a custom .ini location.
I'm asking this firstly because Google has proved fruitless (once again) and secondly because I know it's possible - I've actually done this before, but with only one of my Apps. I accomplished this by launching the App via the command programFile.exe -f configFile.ini /s (I have also seen programFile.exe -d -f configFile.ini /s elsewhere). Naturally, I thought I would try to apply this to some other Apps but it seems it only works for that particular App.
So, is there a command/switch that I am unaware of that will do this for an .exe file?
Thanks
It really depends on each executable file you are using. Some have support for what you are looking for, and some don't. Some programs don't even use .ini files. What you should look for is if each and every program you use have support for user data custom location.
Edit
The only case where generic arguments would be avaialble for a group of EXE files is if they are generated with the same tool, which automatically provides these arguments for you. InstallShield and MSI install programs have that kind of feature (with the silent install and automated installation for instance).
I suggest you look into the tool you are using to generate your portable Apps, and see if it does provide those generic arguments for you, and how they work. If it does not have that feature, then look into the Apps you were able to specify a custom location for your INI file. Somewhere into the code, there must be a piece of code that handles the arguments you specify to the EXE file and handles them. You should share that piece of code with your other Apps, to make sure they provide the same arguments list.

How to make binary which downloads its newer copy?(limitied conditions)

Would like to ask for advice.
there is a need for binary to have a mechanism for self update. Lets imagine binary rolls on host A and updates-server is server B.
Lobster method is to fork bash script with wget/ftp/ncftp/etc getter wich will download and replace. But ehm...there is no such tools on A and they will not be installed.
In short I can't use any external software tools(external to running binary).I can just hardcode mechanism in running binary.
As binary image runs it can load binary(and md5 file) simply via tcp sockets in tmp file,then do md5 compare and if everything ok then replace binary and restart itself. Its easy to do, but I have some strange feeling...dunno.
Mb someone can share and advice?:)Thank you in advance.
Conditions: binary is written in pure c. freebsd is binary rolling side and update-serve is centos. So java/python/c++/any is available at server side but not on free. Y, tobe honest its is possbile install some tools on client side and openfirewall for ftp, but want to avoid and hardcode :)
ADDED: must be noted that the enviroment between A and B is secured..eghm...as we think, in any way security and access problem and spoofing/sniffing out of our world there :) its just local update implementation mechanism for some binary which nowdays we update from center within expect scripts via ssh.
You will have to reimplement a whole host of functionality if you want to do so. My easiest suggestion would be to link to libcurl, hardcode the download path into your executable and write the image of your executable back to $ARGV[0]. However, you should definitely rethink your distribution concept, most distributions do some form of package management, and using it is the easiest alternative for all parties involved.
First of all check if you can modify a binary when a process is executing it, some system does not allow it.
You say you can not use external tool so probbly you can not create another "updater program" which will do the chenge instead of your binary.
Probalby you can download such program (from where you want to downlaod your update), execute it (exec, replaces current process with the new one)
that executed process will download and upded your main one, and then exec to it.

Is it a good way to use system() for database scripts from C?

I was searching for connecting to database from C program. But I thought the ODBC connections, logon and all need some libraries. Also I am having a minimal compiler like Tiny C Compiler which is very fast. I do not want to use any ODBC logic etc which is needed to connect and query the database.
So I am using a method which is as follows.
I use a bteq script (teradata) which will have login, query, logoff commands in that. (FYI bteq is a command line database utility. You can use it similar to mysql.exe in command prompt by going to the path of the exe. You can replace bteq with mysql.exe etc). And I use
system("bteq <myscript.txt >out.txt");
myscript.txt will be like the following..
.logon boxname/user,password;
select date;
.logoff;
The above script will logon to the database and query date (you can change the query and write script according to your database engine and your needs) and give output into out.txt.
Now I will parse the out.txt for the row X column I want using fgetc,fscanf or fgets.
And use the data for checking and send a mail using PHP on any server
system("c:/server/php/php.exe sendmail.php");. We can do the same for many a database engines like mysql, .. etc through a simple C program.
Now my question is Is there any flaw in the above method.
If it is then how can I overcome it. I am asking this question because I think this method is unconventional. Please give your opinions on this method. I don't bother about time needed for execution, RAM used, performance issues etc. I know system() function is time consuming which is not my concern anyway. I also developed specific functions to access query results (similar to accessing a flat file). Please tell me if you have any improvements to this method. If you get to know of any flaws in this please let me know. All kinds of suggestions are welcome.
My environment is : teradata bteq on windows with Tiny C Compiler
This is a perfectly fine way to access an external database, as long as your needs are simple. If you already know about the performance and memory implications of doing this, then there's not much more to say.
The method is fine: it's great to decouple the db subsystem and the parser subsystem by implementing them in an appropriate language.
There's just this tiny little thing - but I may be mistaken because I'm not familiar with bteq: the program will need a bteq script installed in the execution folder; this script will contain username and password. If those aren't encripted in some way, there might be a security flaw.
I wouldn't recommend this if your calling code is running setuid or setgid, but in that case you could use one of the exec() functions instead. (There are a few other considerations you may wish to take into account, all detailed in man 3 system.)

Resources