Skip to content

Commit

Permalink
Avoid duplicate geometry columns, invalid geometry column name in gda…
Browse files Browse the repository at this point in the history
…l points along lines alg
  • Loading branch information
nyalldawson authored and 3nids committed Aug 15, 2017
1 parent c1837ff commit 1b4396d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
14 changes: 13 additions & 1 deletion python/plugins/processing/algs/gdal/ogr2ogrpointsonlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def group(self):
return self.tr('Vector geoprocessing')

def getConsoleCommands(self, parameters, context, feedback):
fields = self.parameterAsSource(parameters, self.INPUT, context).fields()
ogrLayer, layername = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)

distance = str(self.parameterAsDouble(parameters, self.DISTANCE, context))
Expand All @@ -84,6 +85,13 @@ def getConsoleCommands(self, parameters, context, feedback):
output, format = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
options = self.parameterAsString(parameters, self.OPTIONS, context)

other_fields = []
for f in fields:
if f.name() == geometry:
continue

other_fields.append(f.name())

arguments = []
if format:
arguments.append('-f {}'.format(format))
Expand All @@ -94,7 +102,11 @@ def getConsoleCommands(self, parameters, context, feedback):
arguments.append(geometry)
arguments.append(',')
arguments.append(distance)
arguments.append('),*')
arguments.append(')')
arguments.append('AS')
arguments.append(geometry)
arguments.append(',')
arguments.append(','.join(other_fields))
arguments.append('FROM')
arguments.append(layername)
arguments.append('"')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>points_along_lines</Name>
<ElementPath>points_along_lines</ElementPath>
<Name>SELECT</Name>
<ElementPath>SELECT</ElementPath>
<!--POINT-->
<GeometryType>1</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>7</FeatureCount>
<FeatureCount>6</FeatureCount>
<ExtentXMin>-0.50000</ExtentXMin>
<ExtentXMax>7.75000</ExtentXMax>
<ExtentYMin>-3.00000</ExtentYMin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xsi:schemaLocation="http://ogr.maptools.org/ points_along_lines.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
Expand All @@ -12,37 +12,33 @@
</gml:boundedBy>

<gml:featureMember>
<ogr:points_along_lines fid="lines.0">
<ogr:SELECT fid="lines.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7.70710678118655,2.0</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_along_lines>
</ogr:SELECT>
</gml:featureMember>
<gml:featureMember>
<ogr:points_along_lines fid="lines.1">
<ogr:SELECT fid="lines.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-0.5,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_along_lines>
</ogr:SELECT>
</gml:featureMember>
<gml:featureMember>
<ogr:points_along_lines fid="lines.2">
<ogr:SELECT fid="lines.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,1</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_along_lines>
</ogr:SELECT>
</gml:featureMember>
<gml:featureMember>
<ogr:points_along_lines fid="lines.3">
<ogr:SELECT fid="lines.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.5,1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_along_lines>
</ogr:SELECT>
</gml:featureMember>
<gml:featureMember>
<ogr:points_along_lines fid="lines.4">
<ogr:SELECT fid="lines.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7.75,-3.0</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_along_lines>
</ogr:SELECT>
</gml:featureMember>
<gml:featureMember>
<ogr:points_along_lines fid="lines.5">
<ogr:SELECT fid="lines.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-2</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_along_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:points_along_lines fid="lines.6">
</ogr:points_along_lines>
</ogr:SELECT>
</gml:featureMember>
</ogr:FeatureCollection>
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ tests:
OUTPUT:
name: expected/gdal/points_along_lines.gml
type: vector
pk: fid
compare:
ignore_crs_check: true

Expand Down

0 comments on commit 1b4396d

Please sign in to comment.