예제 #1
0
파일: Api.cs 프로젝트: TNOCS/csTouch
 public void TestApis()
 {
     layers.DeleteLayer("testje");
     var l = new Layer
     {
         Id = "testje",
         Title = "test layer",
         Storage = "file",
         Type = "dynamicgeojson",
         Features = new List<Feature>()
     };
     var f = new Feature() {Type = "Feature", Geometry = new Geometry() {Type = "Point", Coordinates = new List<double?>() {5.3, 54.2}}};
     
     try
     {
         layers.AddLayer(l);
         features.AddFeature("testje", f);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
예제 #2
0
파일: FeatureApi.cs 프로젝트: TNOCS/csTouch
        /// <summary>
        /// Update a single pre-existing feature 
        /// </summary>
        /// <param name="body">JSON that will be used to update the feature</param>
        /// <param name="layerId">ID or Name of the Layer to update</param>
        /// <param name="featureId">ID of the feature to update</param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task UpdateFeatureAsync (Feature body, string layerId, string featureId)
        {
            // verify the required parameter 'body' is set
            if (body == null) throw new ApiException(400, "Missing required parameter 'body' when calling UpdateFeature");
            // verify the required parameter 'layerId' is set
            if (layerId == null) throw new ApiException(400, "Missing required parameter 'layerId' when calling UpdateFeature");
            // verify the required parameter 'featureId' is set
            if (featureId == null) throw new ApiException(400, "Missing required parameter 'featureId' when calling UpdateFeature");
    
            const string path = "/layers/{layerId}/feature/{featureId}";
    
            var pathParams = new Dictionary<string, string>();
            var queryParams = new Dictionary<string, string>();
            var headerParams = new Dictionary<string, string>();
            var formParams = new Dictionary<string, string>();
            var fileParams = new Dictionary<string, FileParameter>();

            pathParams.Add("format", "json");
            pathParams.Add("layerId", ApiClient.ParameterToString(layerId)); // path parameter
            pathParams.Add("featureId", ApiClient.ParameterToString(featureId)); // path parameter
            
            var postBody = ApiClient.Serialize(body);
    
            // authentication setting, if any
            string[] authSettings = {  };
    
            // make the HTTP request
            var response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
            if ((int)response.StatusCode >= 400)
                throw new ApiException ((int)response.StatusCode, "Error calling UpdateFeature: " + response.Content, response.Content);
        }
예제 #3
0
파일: SpecialApi.cs 프로젝트: TNOCS/csTouch
        /// <summary>
        /// Gets all and any points that are within a user-supplied polygon in a GeoJSON document. Takes a GeoJSON specification compliant document as input. This method can be used to determine the points within a special area, such as municipial borders.
        /// </summary>
        /// <param name="feature">JSON that will be used to query the layer</param>
        /// <param name="layerId">ID of the layer</param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task GetwithinpolygonAsync (Feature feature, string layerId)
        {
            // verify the required parameter 'feature' is set
            if (feature == null) throw new ApiException(400, "Missing required parameter 'feature' when calling Getwithinpolygon");
            // verify the required parameter 'layerId' is set
            if (layerId == null) throw new ApiException(400, "Missing required parameter 'layerId' when calling Getwithinpolygon");
            
    
            var path = "/layers/{layerId}/getwithinpolygon";
    
            var pathParams = new Dictionary<String, String>();
            var queryParams = new Dictionary<String, String>();
            var headerParams = new Dictionary<String, String>();
            var formParams = new Dictionary<String, String>();
            var fileParams = new Dictionary<String, FileParameter>();
            String postBody = null;
    
            pathParams.Add("format", "json");
            if (layerId != null) pathParams.Add("layerId", ApiClient.ParameterToString(layerId)); // path parameter
            
            
            
            
            postBody = ApiClient.Serialize(feature); // http body (model) parameter
            
    
            // authentication setting, if any
            String[] authSettings = new String[] {  };
    
            // make the HTTP request
            IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
            if (((int)response.StatusCode) >= 400)
                throw new ApiException ((int)response.StatusCode, "Error calling Getwithinpolygon: " + response.Content, response.Content);

            
            return;
        }
예제 #4
0
파일: FeatureApi.cs 프로젝트: TNOCS/csTouch
        /// <summary>
        /// Adds a feature 
        /// </summary>
        /// <param name="layerId">ID of layer to add the feature to</param>
        /// <param name="body">JSON that will be used to insert the feature</param>
        /// <returns>ApiResponse</returns>
        public async System.Threading.Tasks.Task<ApiResponse> AddFeatureAsync (string layerId, Feature body)
        {
            // verify the required parameter 'layerId' is set
            if (layerId == null) throw new ApiException(400, "Missing required parameter 'layerId' when calling AddFeature");
            // verify the required parameter 'body' is set
            if (body == null) throw new ApiException(400, "Missing required parameter 'body' when calling AddFeature");
            
    
            var path = "/layers/{layerId}/feature";
    
            var pathParams = new Dictionary<string, string>();
            var queryParams = new Dictionary<string, string>();
            var headerParams = new Dictionary<string, string>();
            var formParams = new Dictionary<string, string>();
            var fileParams = new Dictionary<string, FileParameter>();

            pathParams.Add("format", "json");
            pathParams.Add("layerId", ApiClient.ParameterToString(layerId)); // path parameter
            
            var postBody = ApiClient.Serialize(body);
    
            // authentication setting, if any
            string[] authSettings = {  };
    
            // make the HTTP request
            var response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
            if (((int)response.StatusCode) >= 400)
                throw new ApiException ((int)response.StatusCode, "Error calling AddFeature: " + response.Content, response.Content);

            //return (ApiResponse) ApiClient.Deserialize(response.Content, typeof(ApiResponse), response.Headers);
            return new ApiResponse() {Code = 200, Message = response.Content};
        }
예제 #5
0
        private void UpdateFeature(Feature f, global::DataServer.PoI p, Layer layer)
        {
            p.Data["cs"] = f;


            if (f.Geometry.Type == "Point")
            {
                if (f.Geometry.Coordinates is object[])
                {
                    var co = (object[])f.Geometry.Coordinates;
                    f.Geometry.Coordinates = new JArray(co);
                }
                var c = ((JArray)f.Geometry.Coordinates).Select(x => (double)x).ToList();

                if (p.Position == null || p.Position.Longitude != c[0] || p.Position.Latitude != c[1])
                {
                    p.Position = new Position(c[0], c[1]);
                }
            }
            if (layer.DefaultFeatureType != null)
            {
                p.PoiTypeId = layer.DefaultFeatureType;
            }
            var t = this.PoITypes.FirstOrDefault((pt) => p.PoiTypeId == pt.PoiId);

            //var type = AppState.f
            //p.PoiTypeId = 
            f.Properties.ForEach((v) =>
            {
                p.Labels[v.Key] = v.Value.ToString();
                var mt = t?.MetaInfo.FirstOrDefault((mi) => mi.Id == v.Key);
                if (mt != null)
                {
                    if (mt.Type == MetaTypes.datetime)
                    {
                        p.TimelineString = this.Layer.ID;
                        DateTime dd;
                        if (DateTime.TryParse(v.Value.ToString(), out dd))
                        {
                            p.Date = dd;
                            this.Events.Add(p);
                        }

                    }
                }
            });
            p.ForceUpdate(true, false);
        }
예제 #6
0
        private global::DataServer.PoI AddFeature(Feature f, Guid id, Layer layer)
        {
            var p = new global::DataServer.PoI { Service = this, Id = id, PoiTypeId = f.Properties.ContainsKey("featureTypeId") ?(string)f.Properties["featureTypeId"]:null };
            UpdateFeature(f, p, layer);


            PoIs.Add(p);
            p.Deleted += (o, s) => { if (IsInitialized) api.features.DeleteFeature(f.Id, layer.Id); };

            var posChanged = Observable.FromEventPattern<PositionEventArgs>(ev => p.PositionChanged += ev,
                ev => p.PositionChanged -= ev);
            posChanged.Throttle(TimeSpan.FromSeconds(1)).Subscribe(k =>
            {
                if (f.Geometry.Coordinates is JArray)
                {
                    var coords = f.Geometry.Coordinates as JArray;
                    if (coords != null &&
                        ((double) coords[0] != p.Position.Longitude || (double) coords[1] != p.Position.Latitude))
                    {
                        ((JArray) f.Geometry.Coordinates)[0] = p.Position.Longitude;
                        ((JArray) f.Geometry.Coordinates)[1] = p.Position.Latitude;
                        //var c = ((JArray) f.Geometry.Coordinates).Select(x => (double) x).ToList();
                        //c[0] = p.Position.Longitude;
                        //c[1] = p.Position.Latitude;
                        //f.Geometry.Coordinates = c;
                        var t = api.features.UpdateFeatureAsync(f, layer.Id, f.Id);
                    }
                }
            });
            return p;
        }
예제 #7
0
 public static void SyncPoi(global::DataServer.PoI p, Layer l, Feature f, csWebApi api)
 {
     if (!p.Data.ContainsKey("cs") || p.Data["cs"] == null)
     {
         p.Data["cs"] = f;
     }
     var posChanged = Observable.FromEventPattern<PositionEventArgs>(ev => p.PositionChanged += ev,
         ev => p.PositionChanged -= ev);
     posChanged.Throttle(TimeSpan.FromSeconds(1)).Subscribe(k =>
     {
         var coords = f.Geometry.Coordinates as JArray;
         if (coords != null && ((double)coords[0] != p.Position.Longitude || (double)coords[1] != p.Position.Latitude))
         {
             ((JArray)f.Geometry.Coordinates)[0] = p.Position.Longitude;
             ((JArray)f.Geometry.Coordinates)[1] = p.Position.Latitude;
             //var c = ((JArray) f.Geometry.Coordinates).Select(x => (double) x).ToList();
             //c[0] = p.Position.Longitude;
             //c[1] = p.Position.Latitude;
             //f.Geometry.Coordinates = c;
             var t = api.features.UpdateFeatureAsync(f, l.Id, f.Id);
         }
     });
 }
예제 #8
0
        public static Feature GetFeatureFromPoi(global::DataServer.PoI p)
        {
            var f = new Feature();
            f.Id = p.Id.ToString();
            f.Geometry = new Geometry();
            f.Type = "Feature";
            switch (p.NEffectiveStyle.DrawingMode.ToString())
            {
                case "Polyline":
                    f.Geometry.Type = "LineString";
                    f.Geometry.Coordinates = new JArray(p.Points.Select(point=>new JArray() {point.X, point.Y}));
                    break;
                case "Polygon":
                    f.Geometry.Type = "Polygon";
                    f.Geometry.Coordinates = new JArray();
                    ((JArray) f.Geometry.Coordinates).Add(
                        new JArray(p.Points.Select(point => new JArray() {point.X, point.Y})));
                    break;
                default:
                    f.Geometry.Type = "Point";
                    f.Geometry.Coordinates = new JArray() { p.Position.Longitude, p.Position.Latitude };
                    break;
            }
            


            f.Properties = new Dictionary<string, object>();
            f.Properties["featureTypeId"] = p.PoiTypeId;
            foreach (var l in p.Labels)
            {
                f.Properties[l.Key] = l.Value;
            }

            //f.Geometry = new IO.Swagger.Model.Geometry();


            return f;
        }