Beispiel #1
0
    public async IAsyncEnumerable <T> DownloadAsync(GeometryBase?geometry, SpatialRel spatialRel, string?whereClause = null, string?extraParameters = null, bool keepQuerying = false)
    {
        var spatialFilter = $"geometry={WebUtility.UrlEncode(geometry?.ToJson())}&geometryType={Layer<T>.ToGeometryType(geometry)}&spatialRel=esriSpatialRel{spatialRel}";

        await foreach (var feature in DownloadAsync(whereClause, string.IsNullOrEmpty(extraParameters) ? spatialFilter : (extraParameters + "&" + spatialFilter), keepQuerying))
        {
            yield return(feature);
        }
    }
Beispiel #2
0
    public IEnumerable <T> Download(GeometryBase?geometry, SpatialRel spatialRel, string?whereClause = null, string?extraParameters = null, bool keepQuerying = false, int degreeOfParallelism = 1, CancellationToken?cancellationToken = null)
    {
        var spatialFilter = $"geometry={WebUtility.UrlEncode(geometry?.ToJson())}&geometryType={Layer<T>.ToGeometryType(geometry)}&spatialRel=esriSpatialRel{spatialRel}";

        return(Download(whereClause, string.IsNullOrEmpty(extraParameters) ? spatialFilter : (extraParameters + "&" + spatialFilter), keepQuerying, degreeOfParallelism, cancellationToken));
    }
Beispiel #3
0
        /// <summary>
        /// Query by geometry
        /// </summary>
        /// <param name="geo">input geometry</param>
        /// <param name="layer">target layer</param>
        /// <returns></returns>
        public List <int> QueryByGeometry(OSGeo.OGR.Geometry geo, OSGeo.OGR.Layer layer, SpatialRel sr)
        {
            List <int> result = new List <int>();

            try
            {
                OSGeo.OGR.Feature oFeature = null;

                while ((oFeature = layer.GetNextFeature()) != null)
                {
                    OSGeo.OGR.Geometry oGeometry = oFeature.GetGeometryRef();
                    switch (sr)
                    {
                    case SpatialQuery.SpatialRel.Undefined: break;

                    case SpatialQuery.SpatialRel.Intersects:
                        if (geo.Intersect(oGeometry))
                        {
                            result.Add((int)oFeature.GetFID());
                        }
                        break;

                    case SpatialQuery.SpatialRel.Contains:
                        if (oGeometry.Contains(geo))
                        {
                            result.Add((int)oFeature.GetFID());
                        }
                        break;

                    case SpatialQuery.SpatialRel.Crosses:
                        if (geo.Crosses(oGeometry))
                        {
                            result.Add((int)oFeature.GetFID());
                        }
                        break;

                    case SpatialQuery.SpatialRel.Overlaps:
                        if (geo.Overlaps(oGeometry))
                        {
                            result.Add((int)oFeature.GetFID());
                        }
                        break;

                    case SpatialQuery.SpatialRel.Touches:
                        if (geo.Touches(oGeometry))
                        {
                            result.Add((int)oFeature.GetFID());
                        }
                        break;

                    case SpatialQuery.SpatialRel.WithIn:
                        if (oGeometry.Within(geo))
                        {
                            result.Add((int)oFeature.GetFID());
                        }
                        break;
                    }
                }
            }
            catch
            {
                throw;
            }

            return(result);
        }
Beispiel #4
0
 public SpatialFilter(OSGeo.OGR.Geometry geo, SpatialRel sr)
 {
     _geo        = geo;
     _spatialRel = sr;
 }
Beispiel #5
0
 /// <summary>
 /// Downloads and yields features whose attributes and geometry are dynamically accessed at runtime.  Possibly throws RestException.
 /// </summary>
 /// <param name="layerName">The name of the feature layer or table.  If the service contains two or more layers with this name, use the overload that takes the layer ID rather than the name.</param>
 /// <param name="whereClause">The where clause.  If set to null, returns all features.</param>
 /// <param name="geometry">The geometry used to spatially filter the records.</param>
 /// <param name="spatialRel">The spatial relationship used for filtering.</param>
 /// <param name="extraParameters">The query string that describes any additional query parameters (i.e. outSR=4326).  Each parameter must be url encoded.</param>
 /// <param name="keepQuerying">If set to true, repetitively queries the server until all features have been returned.</param>
 /// <param name="degreeOfParallelism">The maximum number of concurrent requests.</param>
 /// <returns></returns>
 public IEnumerable <DynamicFeature> Download(string layerName, string whereClause, GeometryBase geometry, SpatialRel spatialRel, string extraParameters = null, bool keepQuerying = false, int degreeOfParallelism = 1)
 {
     return(Download <DynamicFeature>(layerName, whereClause, geometry, spatialRel, extraParameters, keepQuerying, degreeOfParallelism));
 }
Beispiel #6
0
 /// <summary>
 /// Downloads records and yields them as a lazy sequence of features of the specified type.  Possibly throws RestException.
 /// </summary>
 /// <typeparam name="T">The type the record should be mapped to.</typeparam>
 /// <param name="layerName">The name of the feature layer or table.  If the service contains two or more layers with this name, use the overload that takes the layer ID rather than the name.</param>
 /// <param name="whereClause">The where clause.  If set to null, returns all features.</param>
 /// <param name="geometry">The geometry used to spatially filter the records.</param>
 /// <param name="spatialRel">The spatial relationship used for filtering.</param>
 /// <param name="extraParameters">The query string that describes any additional query parameters (i.e. outSR=4326).  Each parameter must be url encoded.</param>
 /// <param name="keepQuerying">If set to true, repetitively queries the server until all features have been returned.</param>
 /// <param name="degreeOfParallelism">The maximum number of concurrent requests.</param>
 /// <returns></returns>
 public IEnumerable <T> Download <T>(string layerName, string whereClause, GeometryBase geometry, SpatialRel spatialRel, string extraParameters = null, bool keepQuerying = false, int degreeOfParallelism = 1) where T : Feature
 {
     return(Download <T>(GetLayer(layerName).id, whereClause, geometry, spatialRel, extraParameters, keepQuerying, degreeOfParallelism));
 }
Beispiel #7
0
        /// <summary>
        /// Downloads records and yields them as a lazy sequence of features of the specified type.  Possibly throws RestException.
        /// </summary>
        /// <typeparam name="T">The type the record should be mapped to.</typeparam>
        /// <param name="layerId">The layer ID of the feature layer or table.</param>
        /// <param name="whereClause">The where clause.  If set to null, returns all features.</param>
        /// <param name="geometry">The geometry used to spatially filter the records.</param>
        /// <param name="spatialRel">The spatial relationship used for filtering.</param>
        /// <param name="extraParameters">The query string that describes any additional query parameters (i.e. outSR=4326).  Each parameter must be url encoded.</param>
        /// <param name="keepQuerying">If set to true, repetitively queries the server until all features have been returned.</param>
        /// <param name="degreeOfParallelism">The maximum number of concurrent requests.</param>
        /// <returns></returns>
        public IEnumerable <T> Download <T>(int layerId, string whereClause, GeometryBase geometry, SpatialRel spatialRel, string extraParameters = null, bool keepQuerying = false, int degreeOfParallelism = 1) where T : Feature
        {
            if (geometry == null)
            {
                return(Download <T>(layerId, whereClause, extraParameters, keepQuerying, degreeOfParallelism));
            }

            string geometryType;

            if (geometry is Point)
            {
                geometryType = "esriGeometryPoint";
            }
            else if (geometry is Multipoint)
            {
                geometryType = "esriGeometryMultipoint";
            }
            else if (geometry is Polyline)
            {
                geometryType = "esriGeometryPolyline";
            }
            else if (geometry is Polygon)
            {
                geometryType = "esriGeometryPolygon";
            }
            else if (geometry is Envelope)
            {
                geometryType = "esriGeometryEnvelope";
            }
            else
            {
                throw new ArgumentException("This geometry type is not supported.", nameof(geometry));
            }

            var spatialFilter = $"geometry={Compatibility.UrlEncode(geometry.ToString())}&geometryType={geometryType}&spatialRel=esriSpatialRel{spatialRel}";

            return(Download <T>(layerId, whereClause, string.IsNullOrEmpty(extraParameters) ? spatialFilter : (extraParameters + "&" + spatialFilter), keepQuerying, degreeOfParallelism));
        }