Skip to content

Commit

Permalink
Make QgsGeometry::offsetCurve handle multi* geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 11, 2016
1 parent 82f4a82 commit 0a2b661
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 5 deletions.
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ multiline_offset.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-1</gml:X><gml:Y>0</gml:Y></gml:coord>
<gml:coord><gml:X>6.024038190337471</gml:X><gml:Y>5.119353882875417</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:multiline_offset fid="lines.1">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>-1,0 1,0</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:multiline_offset>
</gml:featureMember>
<gml:featureMember>
<ogr:multiline_offset fid="lines.2">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>3,2 5,2</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>6.024038190337471,2.397687750474408 5.999853929301003,0.982908479841009</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:multiline_offset>
</gml:featureMember>
<gml:featureMember>
<ogr:multiline_offset fid="lines.3">
</ogr:multiline_offset>
</gml:featureMember>
<gml:featureMember>
<ogr:multiline_offset fid="lines.4">
<ogr:geometryProperty><gml:MultiLineString srsName="EPSG:4326"><gml:lineStringMember><gml:LineString><gml:coordinates>1,0 1,2 1.01921471959677,2.195090322016128 1.076120467488713,2.38268343236509 1.168530387697455,2.555570233019602 1.292893218813453,2.707106781186547 1.444429766980398,2.831469612302545 1.61731656763491,2.923879532511287 1.804909677983872,2.98078528040323 2,3</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>2.915503652020259,5.046801099766013 5.430666799812965,5.119353882875417</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>3.020599614854323,3.999787805420657 5.601021879729563,3.946620818856359</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></ogr:geometryProperty>
</ogr:multiline_offset>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="multiline_offset" type="ogr:multiline_offset_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="multiline_offset_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:GeometryPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
15 changes: 15 additions & 0 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Expand Up @@ -642,3 +642,18 @@ tests:
OUTPUT_LAYER:
name: expected/line_offset_bevel.gml
type: vector

- algorithm: qgis:offsetline
name: Offset multilines
params:
DISTANCE: 1.0
INPUT_LAYER:
name: multilines.gml
type: vector
JOIN_STYLE: '0'
MITRE_LIMIT: 2
SEGMENTS: 8
results:
OUTPUT_LAYER:
name: expected/multiline_offset.gml
type: vector
33 changes: 28 additions & 5 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -1319,13 +1319,36 @@ QgsGeometry QgsGeometry::offsetCurve( double distance, int segments, int joinSty
return QgsGeometry();
}

QgsGeos geos( d->geometry );
QgsAbstractGeometry* offsetGeom = geos.offsetCurve( distance, segments, joinStyle, mitreLimit );
if ( !offsetGeom )
if ( QgsWkbTypes::isMultiType( d->geometry->wkbType() ) )
{
return QgsGeometry();
QList<QgsGeometry> parts = asGeometryCollection();
QList<QgsGeometry> results;
Q_FOREACH ( const QgsGeometry& part, parts )
{
QgsGeometry result = part.offsetCurve( distance, segments, joinStyle, mitreLimit );
if ( result )
results << result;
}
if ( results.isEmpty() )
return QgsGeometry();

QgsGeometry first = results.takeAt( 0 );
Q_FOREACH ( const QgsGeometry& result, results )
{
first.addPart( & result );
}
return first;
}
else
{
QgsGeos geos( d->geometry );
QgsAbstractGeometry* offsetGeom = geos.offsetCurve( distance, segments, joinStyle, mitreLimit );
if ( !offsetGeom )
{
return QgsGeometry();
}
return QgsGeometry( offsetGeom );
}
return QgsGeometry( offsetGeom );
}

QgsGeometry QgsGeometry::simplify( double tolerance ) const
Expand Down

0 comments on commit 0a2b661

Please sign in to comment.