<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi Uwe,<br>
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.<br>
<a class="moz-txt-link-freetext" href="https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly">https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly</a><br>
But I highly recommend upgrading to GRASS7 anyways. Only the
v.in.ogr argument dsn has been changed to input.<br>
Hope it helps.<br>
Best,<br>
Michel<br>
<div class="moz-cite-prefix">On 03/03/2016 01:35 PM, Uwe Fischer
wrote:<br>
</div>
<blockquote cite="mid:003f01d17549$38babe80$aa303b80$@t-online.de"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.E-MailFormatvorlage17
{mso-style-type:personal-compose;
font-family:"Verdana",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif">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. <o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif">The
command line provided by the menu input (in QGIS‘ Grass
toolbox) reads:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"">v.in.ogr dsn=D:/my.dgn output=gr03
type=boundary,centroid snap=0.01 min_area=1 "where="Level" =
1" –o<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif">Searching
the internet for sample scripts, I found some of those and
modified my command string according to the samples:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"">import grass.script as grass<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"">import grass.script.setup as gsetup<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"">gsetup.init(gisbase,gisdbase,location,mapset)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"">input_dgn = "D:\\my.dgn"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New"">grass.run_command("v.in.ogr",<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New""> dsn = input_dgn,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New""> output = 'gr03',<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New""> type = 'boundary,centroid',<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New""> snap = 0.01,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New""> min_area = 1,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New""> where = """"Level" = 1""")<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif">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<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif">Thanks a
lot for help an ideas,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-family:"Verdana",sans-serif;mso-fareast-language:DE">Regards,
Uwe<o:p></o:p></span></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
grass-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/grass-user">http://lists.osgeo.org/mailman/listinfo/grass-user</a></pre>
</blockquote>
<br>
</body>
</html>