Skip to content

Commit

Permalink
v.import: Add layer to the projection check (#1328)
Browse files Browse the repository at this point in the history
Layers in some formats (e.g., GeoPackage) can have different projections, so a test with v.in.ogr
without layer may report a difference although the user specified layer with matching projection for v.import.
  • Loading branch information
wenzeslaus committed Feb 19, 2021
1 parent 304f35e commit 31c1ec2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scripts/v.import/v.import.py
Expand Up @@ -134,12 +134,13 @@ def GDAL_COMPUTE_VERSION(maj, min, rev):
return ((maj) * 1000000 + (min) * 10000 + (rev) * 100)


def is_projection_matching(OGRdatasource):
def is_projection_matching(OGRdatasource, layer):
"""Returns True if current location projection
matches dataset projection, otherwise False"""
try:
grass.run_command('v.in.ogr', input=OGRdatasource, flags='j',
quiet=True)
grass.run_command(
"v.in.ogr", input=OGRdatasource, layer=layer, flags="j", quiet=True
)
return True
except CalledModuleError:
return False
Expand Down Expand Up @@ -216,7 +217,7 @@ def main():
vopts['snap'] = options['snap']

# try v.in.ogr directly
if flags['o'] or is_projection_matching(OGRdatasource):
if flags["o"] or is_projection_matching(OGRdatasource, layers):
try:
grass.run_command('v.in.ogr', input=OGRdatasource,
flags=vflags, overwrite=overwrite, **vopts)
Expand Down

0 comments on commit 31c1ec2

Please sign in to comment.