public override double Execute(QGisService service)
        {
            string tableName = this._data.ToString();

            tableName += (this._dataSize == DataSizeEnum.None ? string.Empty : "_" + (int)this._dataSize);

            var lon = (_random.NextDouble() * 360 - 180).ToString(CultureInfo.GetCultureInfo("en-GB"));
            var lat = (_random.NextDouble() * 180 - 90).ToString(CultureInfo.GetCultureInfo("en-GB"));

            var script = @"#!/usr/bin/env Python

from qgis.core import *
import Queue
import timeit
import random

QgsApplication.setPrefixPath(""" + this._qgisPathPrefix + @""", True)
QgsApplication.initQgis()

uri = QgsDataSourceURI()
uri.setConnection('localhost', '5432', 'spatial_index_comparison', 'postgres', 'boss')
uri.setDataSource('public', '" + tableName + @"', 'geom')

layer = QgsVectorLayer(uri.uri(), 'test', 'postgres')

if not layer.isValid():
    print ""Layer failed to load!""

lon = " + lon + @"
lat = " + lat + @"
distance = " + _distance.ToString(CultureInfo.GetCultureInfo("en-GB")) + @"
point_geometry = QgsGeometry.fromPoint(QgsPoint(lon, lat))
first_point = QgsPoint(lat+distance, lon+distance)
second_point = QgsPoint(lat-distance, lon-distance)
index = QgsSpatialIndex()
for f in layer.getFeatures():
    index.insertFeature(f)
q = Queue.Queue()

def rtreeindex_distanceToRandomPoint():
    ids = index.intersects(QgsRectangle(first_point, second_point))
    for id in ids:
        layer.getFeatures(QgsFeatureRequest().setFilterFid(id)).nextFeature(f)
        if f.geometry().distance(point_geometry) < distance:
            q.put(f)

print timeit.timeit(rtreeindex_distanceToRandomPoint, number=1)";

            return(service.ExecuteScript(script));;
        }
        public override double Execute(QGisService service)
        {
            string tableName = this._data.ToString();

            tableName += (this._dataSize == DataSizeEnum.None ? string.Empty : "_" + (int)this._dataSize);

            if (this._data == DataEnum.countries)
            {
                return(1339.38054286);
            }

            var script = @"#!/usr/bin/env Python

from qgis.core import *
import Queue
import timeit
import random

QgsApplication.setPrefixPath(""" + this._qgisPathPrefix + @""", True)
QgsApplication.initQgis()

uri = QgsDataSourceURI()
uri.setConnection('localhost', '5432', 'spatial_index_comparison', 'postgres', 'boss')
uri.setDataSource('public', '" + tableName + @"', 'geom')

layer = QgsVectorLayer(uri.uri(), 'test', 'postgres')

if not layer.isValid():
    print ""Layer failed to load!""

index = QgsSpatialIndex()
for f in layer.getFeatures():
    index.insertFeature(f)

def rtreeindex_touches():
    for feature in layer.getFeatures():
        ids = index.intersects(feature.geometry().boundingBox())
        for id in ids:
            iter = layer.getFeatures(QgsFeatureRequest().setFilterFid(id)).nextFeature(f)
            if f == feature: continue
            touches = f.geometry().touches(feature.geometry())

print timeit.timeit(rtreeindex_touches, number=1)";

            return(service.ExecuteScript(script));
        }
示例#3
0
        public override double Execute(QGisService service)
        {
            string tableName = this._data.ToString();

            tableName += (this._dataSize == DataSizeEnum.None ? string.Empty : "_" + (int)this._dataSize);

            var script = @"#!/usr/bin/env Python

from qgis.core import *
import Queue
import timeit
import random

QgsApplication.setPrefixPath(""" + this._qgisPathPrefix + @""", True)
QgsApplication.initQgis()

uri = QgsDataSourceURI()
uri.setConnection('localhost', '5432', 'spatial_index_comparison', 'postgres', 'boss')
uri.setDataSource('public', '" + tableName + @"', 'geom')

layer = QgsVectorLayer(uri.uri(), 'test', 'postgres')

if not layer.isValid():
    print ""Layer failed to load!""

k = " + _nearestNeighboursCount + @"
index = QgsSpatialIndex()
for f in layer.getFeatures():
    index.insertFeature(f)

def rtreeindex_nearestNeighbours():
    for feature in layer.getFeatures():
        nearestIds = index.nearestNeighbor(feature.geometry().asPoint(), k)

print timeit.timeit(rtreeindex_nearestNeighbours, number=1)";

            return(service.ExecuteScript(script));
        }
        public override double Execute(QGisService service)
        {
            string tableName = this._data.ToString();
            tableName += (this._dataSize == DataSizeEnum.None ? string.Empty : "_" + (int)this._dataSize);

            if (this._data == DataEnum.countries) return 1339.38054286;

            var script = @"#!/usr/bin/env Python

            from qgis.core import *
            import Queue
            import timeit
            import random

            QgsApplication.setPrefixPath(""" + this._qgisPathPrefix + @""", True)
            QgsApplication.initQgis()

            uri = QgsDataSourceURI()
            uri.setConnection('localhost', '5432', 'spatial_index_comparison', 'postgres', 'boss')
            uri.setDataSource('public', '" + tableName + @"', 'geom')

            layer = QgsVectorLayer(uri.uri(), 'test', 'postgres')

            if not layer.isValid():
            print ""Layer failed to load!""

            index = QgsSpatialIndex()
            for f in layer.getFeatures():
            index.insertFeature(f)

            def rtreeindex_touches():
            for feature in layer.getFeatures():
            ids = index.intersects(feature.geometry().boundingBox())
            for id in ids:
            iter = layer.getFeatures(QgsFeatureRequest().setFilterFid(id)).nextFeature(f)
            if f == feature: continue
            touches = f.geometry().touches(feature.geometry())

            print timeit.timeit(rtreeindex_touches, number=1)";

            return service.ExecuteScript(script);
        }
        public override double Execute(QGisService service)
        {
            string tableName = this._data.ToString();
            tableName += (this._dataSize == DataSizeEnum.None ? string.Empty : "_" + (int)this._dataSize);

            var lon = (_random.NextDouble() * 360 - 180).ToString(CultureInfo.GetCultureInfo("en-GB"));
            var lat = (_random.NextDouble() * 180 - 90).ToString(CultureInfo.GetCultureInfo("en-GB"));

            var script = @"#!/usr/bin/env Python

            from qgis.core import *
            import Queue
            import timeit
            import random

            QgsApplication.setPrefixPath(""" + this._qgisPathPrefix + @""", True)
            QgsApplication.initQgis()

            uri = QgsDataSourceURI()
            uri.setConnection('localhost', '5432', 'spatial_index_comparison', 'postgres', 'boss')
            uri.setDataSource('public', '" + tableName + @"', 'geom')

            layer = QgsVectorLayer(uri.uri(), 'test', 'postgres')

            if not layer.isValid():
            print ""Layer failed to load!""

            lon = " + lon + @"
            lat = " + lat + @"
            distance = " + _distance.ToString(CultureInfo.GetCultureInfo("en-GB")) + @"
            point_geometry = QgsGeometry.fromPoint(QgsPoint(lon, lat))
            first_point = QgsPoint(lat+distance, lon+distance)
            second_point = QgsPoint(lat-distance, lon-distance)
            index = QgsSpatialIndex()
            for f in layer.getFeatures():
            index.insertFeature(f)
            q = Queue.Queue()

            def rtreeindex_distanceToRandomPoint():
            ids = index.intersects(QgsRectangle(first_point, second_point))
            for id in ids:
            layer.getFeatures(QgsFeatureRequest().setFilterFid(id)).nextFeature(f)
            if f.geometry().distance(point_geometry) < distance:
            q.put(f)

            print timeit.timeit(rtreeindex_distanceToRandomPoint, number=1)";

            return service.ExecuteScript(script); ;
        }
        public override double Execute(QGisService service)
        {
            string tableName = this._data.ToString();
            tableName += (this._dataSize == DataSizeEnum.None ? string.Empty : "_" + (int)this._dataSize);

            var script = @"#!/usr/bin/env Python

            from qgis.core import *
            import Queue
            import timeit
            import random

            QgsApplication.setPrefixPath(""" + this._qgisPathPrefix + @""", True)
            QgsApplication.initQgis()

            uri = QgsDataSourceURI()
            uri.setConnection('localhost', '5432', 'spatial_index_comparison', 'postgres', 'boss')
            uri.setDataSource('public', '" + tableName + @"', 'geom')

            layer = QgsVectorLayer(uri.uri(), 'test', 'postgres')

            if not layer.isValid():
            print ""Layer failed to load!""

            k = " + _nearestNeighboursCount + @"
            index = QgsSpatialIndex()
            for f in layer.getFeatures():
            index.insertFeature(f)

            def rtreeindex_nearestNeighbours():
            for feature in layer.getFeatures():
            nearestIds = index.nearestNeighbor(feature.geometry().asPoint(), k)

            print timeit.timeit(rtreeindex_nearestNeighbours, number=1)";

            return service.ExecuteScript(script);
        }