[GRASS-user] v.in.ogr in Python script not working

Michel Wortmann wortmann at pik-potsdam.de
Thu Mar 3 05:24:27 PST 2016


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_it_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/30d26eac/attachment-0001.html>


More information about the grass-user mailing list