Skip to content
Permalink
Browse files

Merge pull request #5248 from alexbruy/network-analysis

[processing] enable network analysis tests
  • Loading branch information
alexbruy committed Sep 25, 2017
2 parents 386d52d + 73d6058 commit c235264d00d3c1ba726520e222ad9f1177668ea9
@@ -74,8 +74,7 @@ class ServiceAreaFromLayer(QgisAlgorithm):
SPEED_FIELD = 'SPEED_FIELD'
DEFAULT_SPEED = 'DEFAULT_SPEED'
TOLERANCE = 'TOLERANCE'
OUTPUT_POINTS = 'OUTPUT_POINTS'
OUTPUT_POLYGON = 'OUTPUT_POLYGON'
OUTPUT = 'OUTPUT'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'networkanalysis.svg'))
@@ -148,14 +147,9 @@ def initAlgorithm(self, config=None):
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(p)

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_POINTS,
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
self.tr('Service area (boundary nodes)'),
QgsProcessing.TypeVectorPoint,
optional=True))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_POLYGON,
self.tr('Service area (convex hull)'),
QgsProcessing.TypeVectorPolygon,
optional=True))
QgsProcessing.TypeVectorPoint))

def name(self):
return 'serviceareafromlayer'
@@ -234,17 +228,8 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.pushInfo(self.tr('Calculating service areas...'))
graph = builder.graph()

results = {}
(sinkPoints, pointsId) = self.parameterAsSink(parameters, self.OUTPUT_POINTS, context,
fields, QgsWkbTypes.MultiPoint, network.sourceCrs())

(sinkPolygon, polygonId) = self.parameterAsSink(parameters, self.OUTPUT_POLYGON, context,
fields, QgsWkbTypes.Polygon, network.sourceCrs())

if sinkPoints:
results[self.OUTPUT_POINTS] = pointsId
if sinkPolygon:
results[self.OUTPUT_POLYGON] = polygonId
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
fields, QgsWkbTypes.MultiPoint, network.sourceCrs())

vertices = []
upperBoundary = []
@@ -268,42 +253,23 @@ def processAlgorithm(self, parameters, context, feedback):
upperBoundary.append(graph.vertex(graph.edge(tree[j]).inVertex()).point())
lowerBoundary.append(graph.vertex(graph.edge(tree[j]).outVertex()).point())

if sinkPoints:
geomUpper = QgsGeometry.fromMultiPoint(upperBoundary)
geomLower = QgsGeometry.fromMultiPoint(lowerBoundary)

feat.setGeometry(geomUpper)
feat['type'] = 'upper'
feat['start'] = origPoint
sinkPoints.addFeature(feat, QgsFeatureSink.FastInsert)

feat.setGeometry(geomLower)
feat['type'] = 'lower'
feat['start'] = origPoint
sinkPoints.addFeature(feat, QgsFeatureSink.FastInsert)

if sinkPolygon:
upperBoundary.append(origPoint)
lowerBoundary.append(origPoint)
geomUpper = QgsGeometry.fromMultiPoint(upperBoundary)
geomLower = QgsGeometry.fromMultiPoint(lowerBoundary)

geom = geomUpper.convexHull()
feat.setGeometry(geom)
feat['type'] = 'upper'
feat['start'] = origPoint
sinkPolygon.addFeature(feat, QgsFeatureSink.FastInsert)

geom = geomLower.convexHull()
feat.setGeometry(geom)
feat['type'] = 'lower'
feat['start'] = origPoint
sinkPolygon.addFeature(feat, QgsFeatureSink.FastInsert)
geomUpper = QgsGeometry.fromMultiPoint(upperBoundary)
geomLower = QgsGeometry.fromMultiPoint(lowerBoundary)

feat.setGeometry(geomUpper)
feat['type'] = 'upper'
feat['start'] = origPoint
sink.addFeature(feat, QgsFeatureSink.FastInsert)

feat.setGeometry(geomLower)
feat['type'] = 'lower'
feat['start'] = origPoint
sink.addFeature(feat, QgsFeatureSink.FastInsert)

vertices[:] = []
upperBoundary[:] = []
lowerBoundary[:] = []

feedback.setProgress(int(i * total))

return results
return {self.OUTPUT: dest_id}
@@ -73,8 +73,7 @@ class ServiceAreaFromPoint(QgisAlgorithm):
SPEED_FIELD = 'SPEED_FIELD'
DEFAULT_SPEED = 'DEFAULT_SPEED'
TOLERANCE = 'TOLERANCE'
OUTPUT_POINTS = 'OUTPUT_POINTS'
OUTPUT_POLYGON = 'OUTPUT_POLYGON'
OUTPUT = 'OUTPUT'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'networkanalysis.svg'))
@@ -146,14 +145,9 @@ def initAlgorithm(self, config=None):
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(p)

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_POINTS,
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
self.tr('Service area (boundary nodes)'),
QgsProcessing.TypeVectorPoint,
optional=True))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_POLYGON,
self.tr('Service area (convex hull)'),
QgsProcessing.TypeVectorPolygon,
optional=True))
QgsProcessing.TypeVectorPoint))

def name(self):
return 'serviceareafrompoint'
@@ -236,43 +230,22 @@ def processAlgorithm(self, parameters, context, feedback):
geomUpper = QgsGeometry.fromMultiPoint(upperBoundary)
geomLower = QgsGeometry.fromMultiPoint(lowerBoundary)

(sinkPoints, pointsId) = self.parameterAsSink(parameters, self.OUTPUT_POINTS, context,
fields, QgsWkbTypes.MultiPoint, network.sourceCrs())

(sinkPolygon, polygonId) = self.parameterAsSink(parameters, self.OUTPUT_POLYGON, context,
fields, QgsWkbTypes.Polygon, network.sourceCrs())
results = {}
if sinkPoints:
feat.setGeometry(geomUpper)
feat['type'] = 'upper'
feat['start'] = startPoint.toString()
sinkPoints.addFeature(feat, QgsFeatureSink.FastInsert)

feat.setGeometry(geomLower)
feat['type'] = 'lower'
feat['start'] = startPoint.toString()
sinkPoints.addFeature(feat, QgsFeatureSink.FastInsert)

upperBoundary.append(startPoint)
lowerBoundary.append(startPoint)
geomUpper = QgsGeometry.fromMultiPoint(upperBoundary)
geomLower = QgsGeometry.fromMultiPoint(lowerBoundary)

results[self.OUTPUT_POINTS] = pointsId

if sinkPolygon:
geom = geomUpper.convexHull()
feat.setGeometry(geom)
feat['type'] = 'upper'
feat['start'] = startPoint.toString()
sinkPolygon.addFeature(feat, QgsFeatureSink.FastInsert)

geom = geomLower.convexHull()
feat.setGeometry(geom)
feat['type'] = 'lower'
feat['start'] = startPoint.toString()
sinkPolygon.addFeature(feat, QgsFeatureSink.FastInsert)

results[self.OUTPUT_POLYGON] = polygonId

return results
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
fields, QgsWkbTypes.MultiPoint, network.sourceCrs())

feat.setGeometry(geomUpper)
feat['type'] = 'upper'
feat['start'] = startPoint.toString()
sink.addFeature(feat, QgsFeatureSink.FastInsert)

feat.setGeometry(geomLower)
feat['type'] = 'lower'
feat['start'] = startPoint.toString()
sink.addFeature(feat, QgsFeatureSink.FastInsert)

upperBoundary.append(startPoint)
lowerBoundary.append(startPoint)
geomUpper = QgsGeometry.fromMultiPoint(upperBoundary)
geomLower = QgsGeometry.fromMultiPoint(lowerBoundary)

return {self.OUTPUT: dest_id}
@@ -1,22 +1,22 @@
<?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/ fastest.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>1000953.579740714</gml:X><gml:Y>6219890.54669478</gml:Y></gml:coord>
<gml:coord><gml:X>1003540.987180206</gml:X><gml:Y>6222358.69755776</gml:Y></gml:coord>
<gml:coord><gml:X>1000993.055595298</gml:X><gml:Y>6219890.54669478</gml:Y></gml:coord>
<gml:coord><gml:X>1003722.680308288</gml:X><gml:Y>6222483.352071707</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:fastest fid="fastest.0">
<ogr:geometryProperty><gml:LineString srsName="EPSG:32733"><gml:coordinates>1000953.57974071,6220312.94386716 1001107.24684923,6220391.87436156 1001202.14148585,6220278.54570253 1001223.5527025,6220254.162188 1001246.61300986,6220217.55052604 1001256.7885771,6220198.09709699 1001288.75671853,6220134.59225221 1001316.12250986,6220076.61143154 1001343.39016642,6220022.54512089 1001398.88208812,6219947.57470368 1001446.00944971,6219890.54669478 1001690.15771473,6220308.37238282 1001859.8438323,6220539.82106708 1002257.84768038,6220937.82878925 1002518.75791724,6221133.53444839 1002622.66996036,6221162.46807726 1002667.16458207,6221195.87188063 1002845.50542017,6221400.90692838 1003028.1814962,6221611.96830289 1003474.59453034,6222127.67457486 1003406.90500878,6222189.64158806 1003472.3070191,6222272.11630568 1003483.81137232,6222286.60579404 1003540.98718021,6222358.69755776</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:start>1000943.66149, 6220332.25337</ogr:start>
<ogr:end>1003534.81686, 6222363.59122</ogr:end>
<ogr:cost>0.0478445</ogr:cost>
<ogr:geometryProperty><gml:LineString srsName="EPSG:32733"><gml:coordinates>1000993.0555953,6220333.22048165 1001107.24684923,6220391.87436156 1001202.14148585,6220278.54570253 1001223.5527025,6220254.162188 1001246.61300986,6220217.55052604 1001256.7885771,6220198.09709699 1001288.75671853,6220134.59225221 1001316.12250986,6220076.61143154 1001343.39016642,6220022.54512089 1001398.88208812,6219947.57470368 1001446.00944971,6219890.54669478 1001690.15771473,6220308.37238282 1001859.8438323,6220539.82106708 1002257.84768038,6220937.82878925 1002518.75791724,6221133.53444839 1002622.66996036,6221162.46807726 1002667.16458207,6221195.87188063 1002845.50542017,6221400.90692838 1003028.1814962,6221611.96830289 1003474.59453034,6222127.67457486 1003406.90500878,6222189.64158806 1003472.3070191,6222272.11630568 1003483.81137232,6222286.60579404 1003602.8338769,6222436.67874613 1003647.3751082,6222401.82100567 1003696.4437017,6222455.04866221 1003722.68030829,6222483.35207171</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:start>1000997.5972, 6220324.37859</ogr:start>
<ogr:end>1003731.87732, 6222474.82666</ogr:end>
<ogr:cost>0.0513153</ogr:cost>
</ogr:fastest>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,45 @@
<?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="fastest" type="ogr:fastest_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="fastest_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:LineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="start" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="254"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="end" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="254"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="cost" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:totalDigits value="21"/>
<xs:fractionDigits value="7"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ service_area.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>1001843.08473263</gml:X><gml:Y>6221162.46807726</gml:Y></gml:coord>
<gml:coord><gml:X>1003040.80096358</gml:X><gml:Y>6222416.40706398</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:service_area fid="service_area.0">
<ogr:geometryProperty><gml:MultiPoint srsName="EPSG:32733"><gml:pointMember><gml:Point><gml:coordinates>1001843.08473263,6221828.62873543</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1001891.40736133,6221430.94581986</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1001940.09434754,6221707.78585671</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1001962.5674552,6222024.23591493</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002086.66939634,6222010.7240816</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002103.66905047,6221324.68154126</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002129.95849754,6222135.73878474</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002299.19357268,6222416.40706398</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002416.57059498,6221277.56159465</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002622.66996036,6221162.46807726</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002667.16458207,6221195.87188063</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002761.33635685,6222354.19324527</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002897.32222975,6222395.42838888</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002897.87933631,6221326.06027793</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1003028.1814962,6221611.96830289</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1003037.55521283,6222118.73863535</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1003040.80096358,6222322.18412711</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometryProperty>
<ogr:type>upper</ogr:type>
<ogr:start>1002465.00896, 6221875.43249</ogr:start>
</ogr:service_area>
</gml:featureMember>
<gml:featureMember>
<ogr:service_area fid="service_area.1">
<ogr:geometryProperty><gml:MultiPoint srsName="EPSG:32733"><gml:pointMember><gml:Point><gml:coordinates>1002015.92985521,6221953.13030737</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1001930.78353526,6221467.36521594</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002045.66496862,6221837.84991727</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002015.92985521,6221953.13030737</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002125.77638469,6222042.5574598</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002275.1898604,6221455.19588041</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002161.08326842,6222058.23120113</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002382.21032908,6222317.66803566</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002275.1898604,6221455.19588041</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002310.58466849,6221563.42200322</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002845.50542017,6221400.90692838</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002724.17727046,6222326.95840711</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002991.11072264,6222281.72914386</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002845.50542017,6221400.90692838</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002657.33259138,6222018.20620536</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002945.17950103,6222241.31856099</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>1002991.11072264,6222281.72914386</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometryProperty>
<ogr:type>lower</ogr:type>
<ogr:start>1002465.00896, 6221875.43249</ogr:start>
</ogr:service_area>
</gml:featureMember>
</ogr:FeatureCollection>

0 comments on commit c235264

Please sign in to comment.
You can’t perform that action at this time.