[GRASS-user] v.in.ogr in Python Grass script

Uwe Fischer gisfisch at t-online.de
Fri Mar 4 02:09:08 PST 2016


Hi Michel, hi List,

In addition to my question from yesterday (concerning v.in.ogr in a Python script), today another item shows up.

I removed the old QGIS from my notebook and installed 2.14 with Grass 7 in order to try that version (following Michels advice). But now I can't get the script running at all. I get an "import error: no module named site" message. The same when I just type "python" at the dos prompt.

I appended the following to the search path (hoping that puts Python to work), but it did not help: 

	C:\Program Files\QGIS Essen\apps\Python27;
	C:\Program Files\QGIS Essen\apps\Python27\Lib;
	C:\Program Files\QGIS Essen\bin


I wonder if the reason is that on the notebook, there is no ordinary Python Installation (Python outside QGIS and GRASS). On my desktop PC (where the script starts fine but crashes before producing output), there is an installation under C:\Python27. There, I get no such error.

Looks like I have no basic understandig for this. So please let me know: are the Python parts that come with QGIS and GRASS a complete Python installation? Or do I have to run an additional Python setup outside QGIS and GRASS to get external scripts running (external script means: scripts that use GRASS commands from outside a GRASS session)??? Maybe the Python parts that get installed along with the GIS are just for internal Python scripting purposes inside QGIS and GRASS sessions?

And if the Python parts of QGIS and GRASS are sufficient for my purpose, how do I have to complete the system setup to get things running (additional path variables? What the h* is "Pythonpath" for? And how to start IDLE?)


Greets, Uwe


-----Ursprüngliche Nachricht-----
Von: Michel Wortmann [mailto:wortmann at pik-potsdam.de] 
Gesendet: Donnerstag, 3. März 2016 17:14
An: grass-user at lists.osgeo.org
Cc: Uwe Fischer <gisfisch at t-online.de>
Betreff: Re: v.in.ogr in Python Grass script

Hi Uwe,
I can really only speak for GRASS7 (and I would almost say this is the way to go). You'll need to give us a working script plus your error messages/tracebacks. Have you tried running your script inside a grass session either from the commandline or inside the python shell that comes with the gui?
Best,
Michel

On 03/03/2016 03:57 PM, Uwe Fischer wrote:
> Michel,
>
> thank you very much for your answer. In my little script, there are more lines above that come from the wiki you referenced, too. I did not want to write them all down here in order to keep it short. Without the environment setup, I got messages like "no such module" when trying to call Grass. But that was the easier part (although hard enough for me, too :-) because I had messages.
>
> Now the problem is that things start working (v.in) and then it crashes without any message. So I have not idea what could be wrong.
>
> Do you really think that Grass 7 makes a diff? The menu command in 6.4.4 works fine. That's confusing to me.
>
> Mit freundlichen Grüßen,
>
> UWE FISCHER
>
> -----Ursprüngliche Nachricht-----
> Von: grass-user [mailto:grass-user-bounces at lists.osgeo.org] Im Auftrag 
> von grass-user-request at lists.osgeo.org
> Gesendet: Donnerstag, 3. März 2016 14:31
> An: grass-user at lists.osgeo.org
> Betreff: grass-user Digest, Vol 119, Issue 4
>
> Send grass-user mailing list submissions to
> 	grass-user at lists.osgeo.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://lists.osgeo.org/mailman/listinfo/grass-user
> or, via email, send a message with subject or body 'help' to
> 	grass-user-request at lists.osgeo.org
>
> You can reach the person managing the list at
> 	grass-user-owner at lists.osgeo.org
>
> When replying, please edit your Subject line so it is more specific than "Re: Contents of grass-user digest..."
>
>
> Today's Topics:
>
>     1. Change GRASS region multiple times (Luna, Daniel Eduardo)
>     2. Re: stream network (Stefan Lüdtke)
>     3. v.in.ogr in Python script not working (Uwe Fischer)
>     4. Re: v.in.ogr in Python script not working (Michel Wortmann)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 2 Mar 2016 21:40:05 +0000
> From: "Luna, Daniel Eduardo" <DEL47 at pitt.edu>
> To: "grass-user at lists.osgeo.org" <grass-user at lists.osgeo.org>
> Cc: "Liang, Xu" <xuliang at pitt.edu>, "Hernandez Cruz, Felipe"
> 	<FEH17 at pitt.edu>
> Subject: [GRASS-user] Change GRASS region multiple times
> Message-ID:
> 	
> <BN3PR0401MB16395B804C952062E8FA8974D7BC0 at BN3PR0401MB1639.namprd04.pro
> d.outlook.com>
> 	
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hello!
>
> I'm working with pygrass, developing a new module for GRASS.
>
> I need to create a new raster map during the execution. I'm using the commands:
>
>          from grass.pygrass import raster
>
>          newRasterMap = raster.RasterSegment('new')
>          newRasterMap.open('w', 'CELL')
>
>
> I've noticed that new raster maps are created with the resolution of the current region in GRASS. I've noticed also that it is possible to change the current region during the execution of my new module using the script 'g.region'. However, it looks like if I want to change the resolution again, the script 'g.region' does not have any effect. My conclusion: GRASS can change the current region just 1 time during the execution of a module. Is that correct?
>
> I would like to know how can I develop a new module (using pygrass) where I could be able to create three new raster maps with different resolutions each?
>
> Thank you all very much!
> --
> Dan
> -------------- next part -------------- An HTML attachment was 
> scrubbed...
> URL: 
> <http://lists.osgeo.org/pipermail/grass-user/attachments/20160302/84eb
> 7d6e/attachment-0001.html>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 3 Mar 2016 10:38:42 +0100
> From: Stefan Lüdtke <sluedtke at gfz-potsdam.de>
> To: Janet Choate <jsc.eco at gmail.com>, Will Fields
> 	<will.openfields at gmail.com>
> Cc: grass list <grass-user at lists.osgeo.org>
> Subject: Re: [GRASS-user] stream network
> Message-ID: <56D80622.1070103 at gfz-potsdam.de>
> Content-Type: text/plain; charset="utf-8"
>
> Hi Janet,
>
> can you provide a screenshot of the river network, I think that helps to understand what is going on in your specific case?!
>
> Cheers,
> Stefan
>
> On 02/03/16 20:42, Janet Choate wrote:
>> Hi Will,
>> When running r.watershed on a small 35 hectare watershed, it produces 
>> a fully connected stream network. However, when running r.watershed 
>> on a
>> 6400 hectare watershed, the stream network is not fully connected.
>> No preprocessing with regards to merging different raster maps, 
>> however, I did try using r.fill.dir first to deal with any possible 
>> depressions that might be causing non-connected stream segments.
>> thanks,
>> Janet
>>
>> On Wed, Mar 2, 2016 at 11:22 AM, Will Fields 
>> <will.openfields at gmail.com <mailto:will.openfields at gmail.com>> wrote:
>>
>>      Hi Janet,
>>
>>      Can you give some more information about what you mean by larger
>>      watershed basins?  Did you do any preprocessing of the elevation
>>      raster before you tried to extract the stream networks?  Were you
>>      using an elevation raster that had been merged from different
>>      rasters?  I've ran into issues in the past where "seams" along the
>>      original edges of a raster resulted in odd stream networks.
>>
>>      Will
>>
>>      On Wed, Mar 2, 2016 at 11:40 AM, Janet Choate <jsc.eco at gmail.com
>>      <mailto:jsc.eco at gmail.com>> wrote:
>>
>>          Hi GRASS community,
>>          When creating a stream network with r.watershed, I end up with
>>          some isolated stream segments - particularly in larger watershed
>>          basins. Does anyone know how to generate a stream network that
>>          is fully connected, or how to correct this issue?
>>          thank you,
>>          Janet
>>
>>
>>
>>          _______________________________________________
>>          grass-user mailing list
>>          grass-user at lists.osgeo.org <mailto:grass-user at lists.osgeo.org>
>>          http://lists.osgeo.org/mailman/listinfo/grass-user
>>
>>
>>
>>
>>
>> --
>> Tague Team Lab Manager
>> 1005 Bren Hall
>> UCSB, Santa Barbara, CA.
>>
>>
>> _______________________________________________
>> grass-user mailing list
>> grass-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/grass-user
>>
> --
> Stefan Lüdtke
>
> Section 5.4-  Hydrology
> Tel.: +49 331 288 2821
> Fax: +49 331 288 1570
> Email: sluedtke at gfz-potsdam.de
>
> Helmholtz-Zentrum Potsdam
> Deutsches GeoForschungsZentrum GFZ
> (GFZ German Research Centre for Geoscience) Stiftung des öff. Rechts 
> Land Brandenburg Telegrafenberg, 14473 Potsdam
> -------------------
>
> PGP Public Key: http://bit.ly/13d9Sca
>
> -------------- next part -------------- A non-text attachment was 
> scrubbed...
> Name: signature.asc
> Type: application/pgp-signature
> Size: 490 bytes
> Desc: OpenPGP digital signature
> URL: 
> <http://lists.osgeo.org/pipermail/grass-user/attachments/20160303/a325
> b3ed/attachment-0001.sig>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 3 Mar 2016 13:35:50 +0100
> From: "Uwe Fischer" <gisfisch at t-online.de>
> To: <grass-user at lists.osgeo.org>
> Subject: [GRASS-user] v.in.ogr in Python script not working
> Message-ID: <003f01d17549$38babe80$aa303b80$@t-online.de>
> Content-Type: text/plain; charset="utf-8"
>
> Hello,
>
>   
>
> I' new to this list and this is my first question. I try to develop a script that is able to import CAD files (MicroStation DGN) into a grass mapset.
> First, I tried the command v.in.ogr in the menu system and everything works fine. The result is exactly as desired. Then, I tried to write a Python script that is able to do exactly the same but without starting GRASS.
>
>   
>
> The command line provided by the menu input (in QGIS' Grass toolbox) reads:
>
>   
>
> v.in.ogr dsn=D:/my.dgn output=gr03 type=boundary,centroid snap=0.01
> min_area=1 "where="Level" = 1" -o
>
>   
>
> Searching the internet for sample scripts, I found some of those and modified my command string according to the samples:
>
>   
>
> import grass.script as grass
>
> import grass.script.setup as gsetup
>
> gsetup.init(gisbase,gisdbase,location,mapset)
>
>   
>
> input_dgn = "D:\\my.dgn"
>
>   
>
> grass.run_command("v.in.ogr",
>
>                    dsn = input_dgn,
>
>                    output = 'gr03',
>
>                    type = 'boundary,centroid',
>
>                    snap = 0.01,
>
>                    min_area = 1,
>
>                    where = """"Level" = 1""")
>
>   
>
>   
>
> Unfortunately, this does not work. I get an error crash message telling me that v.in.ogr does not work any more. I tried many different options, including other use of quotes or leaving some args off. Nothing helped.
> Maybe there is a keyword conflict or an issue with the order of the args?
> The "where" part is very important since it helps me split the data 
> like i need to. I use Grass 6.4.4
>
>   
>
> Thanks a lot for help an ideas,
>
>   
>
> Regards, Uwe
>
> -------------- next part -------------- An HTML attachment was 
> scrubbed...
> URL: 
> <http://lists.osgeo.org/pipermail/grass-user/attachments/20160303/a38b
> ba02/attachment-0001.html>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 3 Mar 2016 14:24:27 +0100
> From: Michel Wortmann <wortmann at pik-potsdam.de>
> To: grass-user at lists.osgeo.org
> Subject: Re: [GRASS-user] v.in.ogr in Python script not working
> Message-ID: <56D83B0B.4010506 at pik-potsdam.de>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Hi Uwe,
> I think you are missing a few environment setup steps if you want to start your python script without starting grass. Here is all you need, although this wiki refers to GRASS7. The grass.setup.init is not enough.
> https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_i
> t_explicitly But I highly recommend upgrading to GRASS7 anyways. Only 
> the v.in.ogr argument dsn has been changed to input.
> Hope it helps.
> Best,
> Michel
> On 03/03/2016 01:35 PM, Uwe Fischer wrote:
>> Hello,
>>
>> I‘ new to this list and this is my first question. I try to develop a 
>> script that is able to import CAD files (MicroStation DGN) into a 
>> grass mapset. First, I tried the command v.in.ogr in the menu system 
>> and everything works fine. The result is exactly as desired. Then, I 
>> tried to write a Python script that is able to do exactly the same 
>> but without starting GRASS.
>>
>> The command line provided by the menu input (in QGIS‘ Grass toolbox)
>> reads:
>>
>> v.in.ogr dsn=D:/my.dgn output=gr03 type=boundary,centroid snap=0.01
>> min_area=1 "where="Level" = 1" –o
>>
>> Searching the internet for sample scripts, I found some of those and 
>> modified my command string according to the samples:
>>
>> import grass.script as grass
>>
>> import grass.script.setup as gsetup
>>
>> gsetup.init(gisbase,gisdbase,location,mapset)
>>
>> input_dgn = "D:\\my.dgn"
>>
>> grass.run_command("v.in.ogr",
>>
>>                    dsn = input_dgn,
>>
>>                    output = 'gr03',
>>
>>                    type = 'boundary,centroid',
>>
>>                    snap = 0.01,
>>
>>                    min_area = 1,
>>
>>                    where = """"Level" = 1""")
>>
>> Unfortunately, this does not work. I get an error crash message 
>> telling me that v.in.ogr does not work any more. I tried many 
>> different options, including other use of quotes or leaving some args 
>> off. Nothing helped. Maybe there is a keyword conflict or an issue 
>> with the order of the args? The „where“ part is very important since 
>> it helps me split the data like i need to. I use Grass 6.4.4
>>
>> Thanks a lot for help an ideas,
>>
>> Regards, Uwe
>>
>>
>>
>> _______________________________________________
>> grass-user mailing list
>> grass-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/grass-user
> -------------- next part -------------- An HTML attachment was 
> scrubbed...
> URL: 
> <http://lists.osgeo.org/pipermail/grass-user/attachments/20160303/30d2
> 6eac/attachment.html>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
>
> ------------------------------
>
> End of grass-user Digest, Vol 119, Issue 4
> ******************************************
>



More information about the grass-user mailing list