Esempio n. 1
0
        public CosmoDbFeatureCursor(CosmoDbFeatureClass fc, IQueryFilter filter)
            : base(fc.SpatialReference, filter.FeatureSpatialReference)
        {
            string sql = String.Empty;

            if (filter is ISpatialFilter)
            {
                ISpatialFilter sFilter = (ISpatialFilter)filter;
                var            env     = sFilter.Geometry.Envelope;

                env.minx = Math.Max(-170, env.minx);
                env.miny = Math.Max(-80, env.miny);
                env.maxx = Math.Min(170, env.maxx);
                env.maxy = Math.Min(80, env.maxy);

                //sql = $"SELECT e._shape FROM everything e WHERE e._fc='{fc.Name}' AND ST_WITHIN(e._shape, {{'type':'Polygon', 'coordinates': [[[{env.miny.ToString(_nhi)}, {env.minx.ToString(_nhi)}], [{env.maxy.ToString(_nhi)}, {env.minx.ToString(_nhi)}], [{env.maxy.ToString(_nhi)}, {env.maxx.ToString(_nhi)}], [{env.miny.ToString(_nhi)}, {env.maxx.ToString(_nhi)}], [{env.miny.ToString(_nhi)}, {env.minx.ToString(_nhi)}]]]}})";
                sql = $"SELECT e._shape FROM everything e WHERE e._fc='{fc.Name}' AND ST_WITHIN(e._shape, {{'type':'Polygon', 'coordinates': [[[{env.minx.ToString(_nhi)}, {env.miny.ToString(_nhi)}], [{env.maxx.ToString(_nhi)}, {env.miny.ToString(_nhi)}], [{env.maxx.ToString(_nhi)}, {env.maxy.ToString(_nhi)}], [{env.minx.ToString(_nhi)}, {env.maxy.ToString(_nhi)}], [{env.minx.ToString(_nhi)}, {env.miny.ToString(_nhi)}]]]}})";
            }
            else
            {
                sql = $"SELECT * FROM everything e WHERE e._fc='{fc.Name}'";
            }

            //var query =
            //    fc.CosmoDocumentClient.CreateDocumentQuery(fc.CosmoDocumentCollection.SelfLink, sql)
            //       .AsEnumerable()
            //       .ToArray();

            _query =
                fc.CosmoDocumentClient.CreateDocumentQuery(fc.CosmoDocumentCollection.SelfLink, sql)
                .AsDocumentQuery();
        }
Esempio n. 2
0
        async static public Task <CosmoDbFeatureClass> Create(CosmoDbDataset dataset, Json.SpatialCollectionItem spatialCollectoinItem)
        {
            var fc = new CosmoDbFeatureClass();

            fc.Dataset = dataset;
            fc.Name    = spatialCollectoinItem.Name;

            if (spatialCollectoinItem.GeometryDef != null)
            {
                fc.HasZ             = spatialCollectoinItem.GeometryDef.HasZ;
                fc.HasM             = spatialCollectoinItem.GeometryDef.HasM;
                fc.GeometryType     = spatialCollectoinItem.GeometryDef.GeometryType;
                fc.SpatialReference = dataset._spatialReference;  // ToDo
            }

            var fields = new Fields();

            if (spatialCollectoinItem.Fields != null)
            {
                foreach (var field in spatialCollectoinItem.Fields)
                {
                    fields.Add(new Field()
                    {
                        name = field.Name,
                        type = field.FieldType
                    });
                }
            }
            fc.Fields = fields;

            fc.CosmoDocumentClient     = dataset._client;
            fc.CosmoDocumentCollection = dataset.GetFeatureCollection(fc.GeometryType);

            fc.Envelope = null;
            using (var cursor = new CosmoDbFeatureCursor(fc, new QueryFilter()))
            {
                IFeature feature = null;
                while ((feature = await cursor.NextFeature()) != null)
                {
                    if (feature.Shape == null)
                    {
                        continue;
                    }

                    if (fc.Envelope == null)
                    {
                        fc.Envelope = feature.Shape.Envelope;
                    }
                    else
                    {
                        fc.Envelope.Union(feature.Shape.Envelope);
                    }
                }
            }

            return(fc);
        }
Esempio n. 3
0
        async public Task <IDatasetElement> Element(string title)
        {
            var result = _client.CreateDocumentQuery <Json.SpatialCollectionItem>(_spatialCollectionRef.SelfLink)
                         .Where(d => d.Name == title)
                         .AsEnumerable <Json.SpatialCollectionItem>()
                         .FirstOrDefault();

            if (result == null)
            {
                return(null);
            }

            return(new DatasetElement(await CosmoDbFeatureClass.Create(this, result))
            {
                Title = result.Name
            });
        }
Esempio n. 4
0
        async public Task <List <IDatasetElement> > Elements()
        {
            if (_layers != null)
            {
                return(_layers);
            }

            List <IDatasetElement> layers = new List <IDatasetElement>();

            foreach (var collectionItem in _client.CreateDocumentQuery <Json.SpatialCollectionItem>(_spatialCollectionRef.SelfLink).AsEnumerable())
            {
                layers.Add(new DatasetElement(await CosmoDbFeatureClass.Create(this, collectionItem)));
            }

            _layers = layers;

            return(_layers);
        }