[GRASS-SVN] r65661 - in grass-addons/grass7/vector: . v.import
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jul 19 12:20:40 PDT 2015
Author: martinl
Date: 2015-07-19 12:20:40 -0700 (Sun, 19 Jul 2015)
New Revision: 65661
Added:
grass-addons/grass7/vector/v.import/v.import.html
grass-addons/grass7/vector/v.import/v.import.py
Removed:
grass-addons/grass7/vector/v.import/v.in.proj.html
grass-addons/grass7/vector/v.import/v.in.proj.py
Modified:
grass-addons/grass7/vector/Makefile
grass-addons/grass7/vector/v.import/Makefile
Log:
rename v.in.proj to v.import (step 2)
Modified: grass-addons/grass7/vector/Makefile
===================================================================
--- grass-addons/grass7/vector/Makefile 2015-07-19 19:18:14 UTC (rev 65660)
+++ grass-addons/grass7/vector/Makefile 2015-07-19 19:20:40 UTC (rev 65661)
@@ -20,6 +20,7 @@
v.external.all \
v.flexure \
v.habitat.dem \
+ v.import \
v.in.geopaparazzi \
v.in.gps \
v.in.ply \
Modified: grass-addons/grass7/vector/v.import/Makefile
===================================================================
--- grass-addons/grass7/vector/v.import/Makefile 2015-07-19 19:18:14 UTC (rev 65660)
+++ grass-addons/grass7/vector/v.import/Makefile 2015-07-19 19:20:40 UTC (rev 65661)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../..
-PGM = v.in.proj
+PGM = v.import
include $(MODULE_TOPDIR)/include/Make/Script.make
Copied: grass-addons/grass7/vector/v.import/v.import.html (from rev 65658, grass-addons/grass7/vector/v.import/v.in.proj.html)
===================================================================
--- grass-addons/grass7/vector/v.import/v.import.html (rev 0)
+++ grass-addons/grass7/vector/v.import/v.import.html 2015-07-19 19:20:40 UTC (rev 65661)
@@ -0,0 +1,41 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.import</em> imports selected layers from a OGR vector datasource
+into the current location and mapset. If the projection of the input
+does not match the projection of the location, the input is reprojected
+into the current location. If the projection of the input does match
+the projection of the location, the input is imported directly with
+<a href="v.in.ogr.html">v.in.ogr</a>.
+
+<h4>Topology cleaning</h4>
+
+When importing polygons, non-topological polygons are converted to
+topological areas. If the original polygons contain errors (unexpected
+overlapping areas or small gaps between polygons), the import might
+need to be repeated using the <em>snap</em> option for
+<a href="v.in.ogr.html">v.in.ogr</a>. In this case, automated import and
+reprojection does not work, and the data need to be manually imported
+first with appropriate settings and optionally cleaned afterwards with
+<a href="v.clean.html">v.clean</a>. The cleaned import can then be
+manually reprojected to the target location.
+
+<h2>EXAMPLE</h2>
+
+<div class="code"><pre>
+# import SHAPE file at full extent and reproject to current location projection
+v.import input=research_area.shp output=research_area extents=input
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.in.ogr.html">v.in.ogr</a>,
+<a href="v.proj.html">v.proj</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Markus Metz
+
+<p>
+<i>Last changed: $Date: 2015-01-20 20:52:27 +0100 (Tue, 20 Jan 2015) $</i>
Copied: grass-addons/grass7/vector/v.import/v.import.py (from rev 65658, grass-addons/grass7/vector/v.import/v.in.proj.py)
===================================================================
--- grass-addons/grass7/vector/v.import/v.import.py (rev 0)
+++ grass-addons/grass7/vector/v.import/v.import.py 2015-07-19 19:20:40 UTC (rev 65661)
@@ -0,0 +1,199 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE: v.import
+#
+# AUTHOR(S): Markus Metz
+#
+# PURPOSE: Import and reproject vector data on the fly
+#
+# COPYRIGHT: (C) 2015 by GRASS development team
+#
+# This program is free software under the GNU General
+# Public License (>=v2). Read the file COPYING that
+# comes with GRASS for details.
+#
+#############################################################################
+
+#%module
+#% description: Imports vector data into a GRASS vector map using OGR library and reproject on the fly.
+#% keyword: vector
+#% keyword: import
+#% keyword: projection
+#%end
+#%option
+#% key: input
+#% type: string
+#% required: yes
+#% description: Name of OGR datasource to be imported
+#% gisprompt: old,datasource,datasource
+#%end
+#%option
+#% key: layer
+#% type: string
+#% multiple: yes
+#% description: OGR layer name. If not given, all available layers are imported
+#% guisection: Input
+#% gisprompt: old,datasource_layer,datasource_layer
+#%end
+#%option G_OPT_V_OUTPUT
+#% description: Name for output vector map (default: input)
+#% guisection: Output
+#%end
+#%option
+#% key: extents
+#% type: string
+#% required: yes
+#% options: input,region
+#% description: Ouput vector map extents
+#% descriptions: region;extents of current region;input;extents of input map
+#% guisection: Output
+#%end
+
+
+import sys
+import os
+import shutil
+import atexit
+import math
+
+import grass.script as grass
+
+
+def cleanup():
+ # remove temp location
+ if tmploc:
+ grass.try_rmdir(os.path.join(gisdbase, tmploc))
+ if srcgisrc:
+ grass.try_remove(srcgisrc)
+
+def main():
+ global tmploc, srcgisrc, gisdbase
+
+ OGRdatasource = options['input']
+ output = options['output']
+ layers = options['layer']
+
+ # initialize global vars
+ tmploc = None
+ srcgisrc = None
+ gisdbase = None
+
+ vflags = None
+ if options['extents'] == 'region':
+ vflags = 'r'
+
+ grassenv = grass.gisenv()
+ tgtloc = grassenv['LOCATION_NAME']
+ tgtmapset = grassenv['MAPSET']
+ gisdbase = grassenv['GISDBASE']
+ tgtgisrc = os.environ['GISRC']
+ srcgisrc = grass.tempfile()
+
+ tmploc = 'temp_import_location_' + str(os.getpid())
+
+ f = open(srcgisrc, 'w')
+ f.write('MAPSET: PERMANENT\n')
+ f.write('GISDBASE: %s\n' % gisdbase)
+ f.write('LOCATION_NAME: %s\n' % tmploc);
+ f.write('GUI: text\n')
+ f.close()
+
+ tgtsrs = grass.read_command('g.proj', flags = 'j', quiet = True)
+
+ # create temp location from input without import
+ grass.message(_("Creating temporary location for <%s>...") % OGRdatasource)
+ returncode = grass.run_command('v.in.ogr', input = OGRdatasource,
+ layer = layers, output = output,
+ location = tmploc, flags = 'i', quiet = True)
+ # if it fails, return
+ if returncode != 0:
+ grass.fatal(_("Unable to create location from OGR datasource <%s>") % OGRdatasource)
+
+ # switch to temp location
+ os.environ['GISRC'] = str(srcgisrc)
+
+ # compare source and target srs
+ insrs = grass.read_command('g.proj', flags = 'j', quiet = True)
+
+ # switch to target location
+ os.environ['GISRC'] = str(tgtgisrc)
+
+ if insrs == tgtsrs:
+ # try v.in.ogr directly
+ grass.message(_("Importing <%s>...") % OGRdatasource)
+ returncode = grass.run_command('v.in.ogr', input = OGRdatasource,
+ layer = layers, output = output,
+ flags = vflags)
+ # if it succeeds, return
+ if returncode == 0:
+ grass.message(_("Input <%s> successfully imported without reprojection") % OGRdatasource)
+ return 0
+ else:
+ grass.fatal(_("Unable to import <%s>") % OGRdatasource)
+
+ # make sure target is not xy
+ if grass.parse_command('g.proj', flags = 'g')['name'] == 'xy_location_unprojected':
+ grass.fatal(_("Coordinate reference system not available for current location <%s>") % tgtloc)
+
+ # switch to temp location
+ os.environ['GISRC'] = str(srcgisrc)
+
+ # make sure input is not xy
+ if grass.parse_command('g.proj', flags = 'g')['name'] == 'xy_location_unprojected':
+ grass.fatal(_("Coordinate reference system not available for input <%s>") % GDALdatasource)
+
+ if options['extents'] == 'region':
+ # switch to target location
+ os.environ['GISRC'] = str(tgtgisrc)
+
+ # v.in.region in tgt
+ vreg = 'vreg_' + str(os.getpid())
+ grass.run_command('v.in.region', output = vreg, quiet = True)
+
+ # reproject to src
+ # switch to temp location
+ os.environ['GISRC'] = str(srcgisrc)
+ returncode = grass.run_command('v.proj', input = vreg, output = vreg,
+ location = tgtloc, mapset = tgtmapset, quiet = True)
+
+ if returncode != 0:
+ grass.fatal(_("Unable to reproject to source location"))
+
+ # set region from region vector
+ grass.run_command('g.region', res = '1')
+ grass.run_command('g.region', vector = vreg)
+
+
+ # import into temp location
+ grass.message(_("Importing <%s> ...") % OGRdatasource)
+ returncode = grass.run_command('v.in.ogr', input = OGRdatasource,
+ layer = layers, output = output,
+ flags = vflags, verbose = True)
+
+ # if it fails, return
+ if returncode != 0:
+ grass.fatal(_("Unable to import OGR datasource <%s>") % OGRdatasource)
+
+ # switch to target location
+ os.environ['GISRC'] = str(tgtgisrc)
+
+ if options['extents'] == 'region':
+ grass.run_command('g.remove', type = 'vector', name = vreg,
+ flags = 'f', quiet = True)
+
+ # v.proj
+ grass.message(_("Reprojecting <%s>...") % output)
+ returncode = grass.run_command('v.proj', location = tmploc,
+ mapset = 'PERMANENT', input = output,
+ quiet = True)
+ if returncode != 0:
+ grass.fatal(_("Unable to to reproject vector <%s>") % output)
+
+ return 0
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ atexit.register(cleanup)
+ sys.exit(main())
Deleted: grass-addons/grass7/vector/v.import/v.in.proj.html
===================================================================
--- grass-addons/grass7/vector/v.import/v.in.proj.html 2015-07-19 19:18:14 UTC (rev 65660)
+++ grass-addons/grass7/vector/v.import/v.in.proj.html 2015-07-19 19:20:40 UTC (rev 65661)
@@ -1,40 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>v.in.proj</em> imports selected layers from a OGR vector datasource
-into the current location and mapset. If the projection of the input
-does not match the projection of the location, the input is reprojected
-into the current location. If the projection of the input does match
-the projection of the location, the input is imported directly with
-<a href="v.in.ogr.html">v.in.ogr</a>.
-
-<h4>Topology cleaning</h4>
-
-When importing polygons, non-topological polygons are converted to
-topological areas. If the original polygons contain errors (unexpected
-overlapping areas or small gaps between polygons), the import might
-need to be repeated using the <em>snap</em> option for
-<a href="v.in.ogr.html">v.in.ogr</a>. In this case, automated import and
-reprojection does not work, and the data need to be manually imported
-first with appropriate settings and optionally cleaned afterwards with
-<a href="v.clean.html">v.clean</a>. The cleaned import can then be
-manually reprojected to the target location.
-
-<h2>EXAMPLE</h2>
-
-<div class="code"><pre>
-# import SHAPE file at full extent and reproject to current location projection
-v.in.proj input_file=research_area.shp out=research_area extents=input
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="v.in.ogr.html">v.in.ogr</a>,
-<a href="v.proj.html">v.proj</a>
-</em>
-
-<h2>AUTHOR</h2>
-
-Markus Metz
-
-<p><i>Last changed: $Date: 2015-01-20 20:52:27 +0100 (Tue, 20 Jan 2015) $</i>
Deleted: grass-addons/grass7/vector/v.import/v.in.proj.py
===================================================================
--- grass-addons/grass7/vector/v.import/v.in.proj.py 2015-07-19 19:18:14 UTC (rev 65660)
+++ grass-addons/grass7/vector/v.import/v.in.proj.py 2015-07-19 19:20:40 UTC (rev 65661)
@@ -1,199 +0,0 @@
-#!/usr/bin/env python
-
-############################################################################
-#
-# MODULE: v.in.proj
-#
-# AUTHOR(S): Markus Metz
-#
-# PURPOSE: Import and reproject vector data on the fly
-#
-# COPYRIGHT: (C) 2015 by GRASS development team
-#
-# This program is free software under the GNU General
-# Public License (>=v2). Read the file COPYING that
-# comes with GRASS for details.
-#
-#############################################################################
-
-#%module
-#% description: Imports vector data into a GRASS vector map using OGR library and reproject on the fly.
-#% keyword: vector
-#% keyword: import
-#% keyword: projection
-#%end
-#%option
-#% key: input
-#% type: string
-#% required: yes
-#% description: Name of OGR datasource to be imported
-#% gisprompt: old,datasource,datasource
-#%end
-#%option
-#% key: layer
-#% type: string
-#% multiple: yes
-#% description: OGR layer name. If not given, all available layers are imported
-#% guisection: Input
-#% gisprompt: old,datasource_layer,datasource_layer
-#%end
-#%option G_OPT_V_OUTPUT
-#% description: Name for output vector map (default: input)
-#% guisection: Output
-#%end
-#%option
-#% key: extents
-#% type: string
-#% required: yes
-#% options: input,region
-#% description: Ouput vector map extents
-#% descriptions: region;extents of current region;input;extents of input map
-#% guisection: Output
-#%end
-
-
-import sys
-import os
-import shutil
-import atexit
-import math
-
-import grass.script as grass
-
-
-def cleanup():
- # remove temp location
- if tmploc:
- grass.try_rmdir(os.path.join(gisdbase, tmploc))
- if srcgisrc:
- grass.try_remove(srcgisrc)
-
-def main():
- global tmploc, srcgisrc, gisdbase
-
- OGRdatasource = options['input']
- output = options['output']
- layers = options['layer']
-
- # initialize global vars
- tmploc = None
- srcgisrc = None
- gisdbase = None
-
- vflags = None
- if options['extents'] == 'region':
- vflags = 'r'
-
- grassenv = grass.gisenv()
- tgtloc = grassenv['LOCATION_NAME']
- tgtmapset = grassenv['MAPSET']
- gisdbase = grassenv['GISDBASE']
- tgtgisrc = os.environ['GISRC']
- srcgisrc = grass.tempfile()
-
- tmploc = 'temp_import_location_' + str(os.getpid())
-
- f = open(srcgisrc, 'w')
- f.write('MAPSET: PERMANENT\n')
- f.write('GISDBASE: %s\n' % gisdbase)
- f.write('LOCATION_NAME: %s\n' % tmploc);
- f.write('GUI: text\n')
- f.close()
-
- tgtsrs = grass.read_command('g.proj', flags = 'j', quiet = True)
-
- # create temp location from input without import
- grass.message(_("Creating temporary location for <%s>...") % OGRdatasource)
- returncode = grass.run_command('v.in.ogr', input = OGRdatasource,
- layer = layers, output = output,
- location = tmploc, flags = 'i', quiet = True)
- # if it fails, return
- if returncode != 0:
- grass.fatal(_("Unable to create location from OGR datasource <%s>") % OGRdatasource)
-
- # switch to temp location
- os.environ['GISRC'] = str(srcgisrc)
-
- # compare source and target srs
- insrs = grass.read_command('g.proj', flags = 'j', quiet = True)
-
- # switch to target location
- os.environ['GISRC'] = str(tgtgisrc)
-
- if insrs == tgtsrs:
- # try v.in.ogr directly
- grass.message(_("Importing <%s>...") % OGRdatasource)
- returncode = grass.run_command('v.in.ogr', input = OGRdatasource,
- layer = layers, output = output,
- flags = vflags)
- # if it succeeds, return
- if returncode == 0:
- grass.message(_("Input <%s> successfully imported without reprojection") % OGRdatasource)
- return 0
- else:
- grass.fatal(_("Unable to import <%s>") % OGRdatasource)
-
- # make sure target is not xy
- if grass.parse_command('g.proj', flags = 'g')['name'] == 'xy_location_unprojected':
- grass.fatal(_("Coordinate reference system not available for current location <%s>") % tgtloc)
-
- # switch to temp location
- os.environ['GISRC'] = str(srcgisrc)
-
- # make sure input is not xy
- if grass.parse_command('g.proj', flags = 'g')['name'] == 'xy_location_unprojected':
- grass.fatal(_("Coordinate reference system not available for input <%s>") % GDALdatasource)
-
- if options['extents'] == 'region':
- # switch to target location
- os.environ['GISRC'] = str(tgtgisrc)
-
- # v.in.region in tgt
- vreg = 'vreg_' + str(os.getpid())
- grass.run_command('v.in.region', output = vreg, quiet = True)
-
- # reproject to src
- # switch to temp location
- os.environ['GISRC'] = str(srcgisrc)
- returncode = grass.run_command('v.proj', input = vreg, output = vreg,
- location = tgtloc, mapset = tgtmapset, quiet = True)
-
- if returncode != 0:
- grass.fatal(_("Unable to reproject to source location"))
-
- # set region from region vector
- grass.run_command('g.region', res = '1')
- grass.run_command('g.region', vector = vreg)
-
-
- # import into temp location
- grass.message(_("Importing <%s> ...") % OGRdatasource)
- returncode = grass.run_command('v.in.ogr', input = OGRdatasource,
- layer = layers, output = output,
- flags = vflags, verbose = True)
-
- # if it fails, return
- if returncode != 0:
- grass.fatal(_("Unable to import OGR datasource <%s>") % OGRdatasource)
-
- # switch to target location
- os.environ['GISRC'] = str(tgtgisrc)
-
- if options['extents'] == 'region':
- grass.run_command('g.remove', type = 'vector', name = vreg,
- flags = 'f', quiet = True)
-
- # v.proj
- grass.message(_("Reprojecting <%s>...") % output)
- returncode = grass.run_command('v.proj', location = tmploc,
- mapset = 'PERMANENT', input = output,
- quiet = True)
- if returncode != 0:
- grass.fatal(_("Unable to to reproject vector <%s>") % output)
-
- return 0
-
-if __name__ == "__main__":
- options, flags = grass.parser()
- atexit.register(cleanup)
- sys.exit(main())
More information about the grass-commit
mailing list