コード例 #1
0
        public static JsonObject ToJsonObject(this IRouteLocation2 routeLocation)
        {
            var output = new JsonObject();

            output.AddString("routeId", $"{routeLocation.RouteID}");
            if (routeLocation is IRouteMeasurePointLocation pointLoc)
            {
                output.AddDouble("measure", pointLoc.Measure);
            }
            else if (routeLocation is IRouteMeasureLineLocation lineLoc)
            {
                output.AddDouble("fromMeasure", lineLoc.FromMeasure);
                output.AddDouble("toMeasure", lineLoc.ToMeasure);
            }
            return(output);
        }
コード例 #2
0
        /// <summary>
        /// Handler operation Identify Route
        /// </summary>
        /// <param name="boundVariables">list of variables bound</param>
        /// <param name="operationInput">input of operation</param>
        /// <param name="outputFormat">format of output</param>
        /// <param name="requestProperties">list of request properties</param>
        /// <param name="responseProperties">list of response properties </param>
        /// <returns>response in byte</returns>
        private byte[] IdentifyRouteOperHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";
            string methodName   = MethodBase.GetCurrentMethod().Name;
            int    routeLayerID = Convert.ToInt32(boundVariables["RouteLayersID"], CultureInfo.InvariantCulture);

            esriUnits routeMeasureUnit = DSUtility.GetMeasureUnit(operationInput, MeasureUnit.routeMeasureUnit);

            IFeatureClass  featureClass          = this.GetRouteFeatureClass(routeLayerID);
            string         routeIDFieldNameValue = DSUtility.GetRouteIDFieldName(operationInput, featureClass.OIDFieldName);
            IRouteLocator2 routeLocator          = DSUtility.GetRouteLocator(featureClass, routeIDFieldNameValue, routeMeasureUnit);

            double?tolerance;
            bool   found = operationInput.TryGetAsDouble("tolerance", out tolerance);

            if (!found || !tolerance.HasValue)
            {
                tolerance = 0.0;
            }

            JsonObject jsonLocation;

            if (!operationInput.TryGetJsonObject("location", out jsonLocation))
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            IPoint location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPoint) as IPoint;

            if (location == null)
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            IEnvelope envelope = location.Envelope;

            envelope.Expand(tolerance.Value, tolerance.Value, false);

            IRouteMeasurePointLocation routeMeasurePointLocation = new RouteMeasurePointLocationClass();
            IRouteLocation             routeLocation;
            IFeature   feature;
            JsonObject result = new JsonObject();

            List <JsonObject>        measures   = new List <JsonObject>();
            IEnumRouteIdentifyResult enumResult = routeLocator.Identify(envelope, string.Empty);

            for (int i = 1; i <= enumResult.Count; i++)
            {
                enumResult.Next(out routeLocation, out feature);
                routeMeasurePointLocation = (IRouteMeasurePointLocation)routeLocation;
                JsonObject measure = new JsonObject();
                measure.AddString("routeID", routeLocation.RouteID.ToString());
                measure.AddDouble("measure", routeMeasurePointLocation.Measure);
                measures.Add(measure);
            }

            result.AddArray("location", measures.ToArray());

            return(result.JsonByte());
        }
コード例 #3
0
        /// <summary>
        /// Handler operation Identify Route Ex
        /// </summary>
        /// <param name="boundVariables">list of variables bound</param>
        /// <param name="operationInput">input of operation</param>
        /// <param name="outputFormat">format of output</param>
        /// <param name="requestProperties">list of request properties</param>
        /// <param name="responseProperties">list of response properties </param>
        /// <returns>response in byte</returns>
        private byte[] IdentifyRouteExOperHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";
            string methodName   = MethodBase.GetCurrentMethod().Name;
            int    routeLayerID = Convert.ToInt32(boundVariables["RouteLayersID"], CultureInfo.InvariantCulture);

            esriUnits            routeMeasureUnit = DSUtility.GetMeasureUnit(operationInput, MeasureUnit.routeMeasureUnit);
            esriSegmentExtension segmentExtension = DSUtility.GetSegmentExtension(operationInput);
            IFeatureClass        featureClass     = this.GetRouteFeatureClass(routeLayerID);

            JsonObject jsonLocation;

            if (!operationInput.TryGetJsonObject("location", out jsonLocation))
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            IPoint location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPoint) as IPoint;

            if (location == null)
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            string  routeIDFieldNameValue = DSUtility.GetRouteIDFieldName(operationInput);
            IFields fields     = featureClass.Fields;
            int     indexField = fields.FindField(routeIDFieldNameValue);

            if (indexField == -1)
            {
                throw new DynamicSegmentationException(string.Format(CultureInfo.InvariantCulture, "routeIDFieldName {0} not found!", routeIDFieldNameValue));
            }

            object routeID;
            bool   found = operationInput.TryGetObject("routeID", out routeID);

            if (!found)
            {
                throw new DynamicSegmentationException("routeID not valid");
            }

            double?tolerance;

            found = operationInput.TryGetAsDouble("tolerance", out tolerance);
            if (!found || !tolerance.HasValue)
            {
                tolerance = 0.0;
            }

            IField field = fields.get_Field(indexField);

            this.CheckRouteID(routeID, field);

            IRouteLocator2 routeLocator = DSUtility.GetRouteLocator(featureClass, routeIDFieldNameValue, routeMeasureUnit);

            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.SubFields = routeLocator.RouteIDFieldName;
            queryFilter.AddField(routeLocator.RouteFeatureClass.ShapeFieldName);
            string where            = string.Format("{0} = {1}{2}{1}", routeLocator.RouteIDFieldNameDelimited, routeLocator.RouteIDIsString ? "'" : string.Empty, routeID);
            queryFilter.WhereClause = where;

            IPoint         locationNearest = null;
            IFeatureCursor featureCursor   = null;

            try
            {
                featureCursor = routeLocator.RouteFeatureClass.Search(queryFilter, true);
                IFeature featureRoute = featureCursor.NextFeature();
                if (featureRoute == null)
                {
                    throw new DynamicSegmentationException(string.Format(CultureInfo.InvariantCulture, "Feature with value {0} not found!", routeID));
                }

                IProximityOperator proximityOperator = featureRoute.ShapeCopy as IProximityOperator;
                locationNearest = proximityOperator.ReturnNearestPoint(location, segmentExtension);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (featureCursor != null)
                {
                    Marshal.ReleaseComObject(featureCursor);
                }
            }

            IEnvelope envelope = locationNearest.Envelope;

            envelope.Expand(tolerance.Value, tolerance.Value, false);

            IRouteMeasurePointLocation routeMeasurePointLocation = new RouteMeasurePointLocationClass();
            IRouteLocation             routeLocation;
            IFeature   feature;
            JsonObject result = new JsonObject();

            List <JsonObject>        measures   = new List <JsonObject>();
            IEnumRouteIdentifyResult enumResult = routeLocator.Identify(envelope, where);

            for (int i = 1; i <= enumResult.Count; i++)
            {
                enumResult.Next(out routeLocation, out feature);
                routeMeasurePointLocation = (IRouteMeasurePointLocation)routeLocation;
                JsonObject measure = new JsonObject();
                measure.AddString("routeID", routeLocation.RouteID.ToString());
                measure.AddDouble("measure", routeMeasurePointLocation.Measure);
                measure.AddJsonObject("location", Conversion.ToJsonObject(locationNearest, true));
                measures.Add(measure);
            }

            result.AddArray("location", measures.ToArray());

            return(result.JsonByte());
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: 305120262/CachedLayerSystem
        /// <summary>
        /// Build Cache Backgroud worker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            int           size   = int.Parse(this.tbxSize.Text);
            IFeatureClass fc_poi = m_fcName.Open() as IFeatureClass;
            IGeoDataset   ds_poi = fc_poi as IGeoDataset;
            int           xmin   = (int)Math.Floor(ds_poi.Extent.XMin);
            int           ymin   = (int)Math.Floor(ds_poi.Extent.YMin);
            int           xmax   = (int)Math.Ceiling(ds_poi.Extent.XMax);
            int           ymax   = (int)Math.Ceiling(ds_poi.Extent.YMax);

            List <JsonObject> ls_fields_cache = new List <JsonObject>();

            if (!(fc_poi.Extension is IAnnotationClassExtension))
            {
                for (int i = 0; i < fc_poi.Fields.FieldCount; i++)
                {
                    IField     field = fc_poi.Fields.get_Field(i);
                    JsonObject js_f  = new JsonObject();
                    js_f.AddString("name", field.Name);
                    js_f.AddString("type", Enum.GetName(typeof(esriFieldType), field.Type));
                    js_f.AddString("alias", field.AliasName);
                    if (field.Type == esriFieldType.esriFieldTypeString)
                    {
                        js_f.AddString("length", field.Length.ToString());
                    }
                    else
                    {
                        js_f.AddString("length", "");
                    }
                    ls_fields_cache.Add(js_f);
                }
            }

            IDatabase client  = m_redis.GetDatabase();
            int       grid_id = 0;
            string    ns      = "poi:" + this.tbxCacheName.Text + ":";

            for (int y = ymin; y <= ymax; y += size)
            {
                for (int x = xmin; x <= xmax; x += size)
                {
                    List <String>     str_poi_grid = new List <String>();
                    List <JsonObject> ls_features  = new List <JsonObject>();
                    //String str_response = client.StringGet(ns+"response");
                    //JsonObject response = new JsonObject(str_response);
                    JsonObject response = new JsonObject();
                    IEnvelope  box      = new EnvelopeClass();
                    box.XMin = x;
                    box.YMin = y;
                    box.XMax = x + size;
                    box.YMax = y + size;
                    ISpatialFilter filter_poi = new SpatialFilterClass();
                    filter_poi.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    filter_poi.Geometry   = box;
                    filter_poi.SubFields  = "*";
                    IFeatureCursor cur_poi = fc_poi.Search(filter_poi, true);
                    IFeature       fea_poi = cur_poi.NextFeature();
                    while (fea_poi != null)
                    {
                        JsonObject js_fea = new JsonObject();
                        if (!(fea_poi is IAnnotationFeature))
                        {
                            JsonObject js_attributes = new JsonObject();
                            int        i             = 0;
                            foreach (JsonObject js_field in ls_fields_cache)
                            {
                                object value = fea_poi.get_Value(i);
                                string fieldtype;
                                js_field.TryGetString("type", out fieldtype);
                                string fieldname;
                                js_field.TryGetString("name", out fieldname);
                                #region
                                if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeString))
                                {
                                    js_attributes.AddString(fieldname, value.ToString());
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeOID))
                                {
                                    js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeInteger))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = 0;
                                    }
                                    js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeSmallInteger))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = 0;
                                    }
                                    js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeDouble))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = 0;
                                    }
                                    js_attributes.AddDouble(fieldname, double.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeDate))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = DateTime.MinValue;
                                    }
                                    js_attributes.AddDate(fieldname, DateTime.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeSingle))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = 0;
                                    }
                                    js_attributes.AddBoolean(fieldname, bool.Parse(value.ToString()));
                                }
                                #endregion
                                i++;
                            }
                            js_fea.AddJsonObject("attributes", js_attributes);
                            js_fea.AddJsonObject("geometry", Conversion.ToJsonObject(fea_poi.Shape));
                        }
                        else
                        {
                            IAnnotationFeature anno_fea = fea_poi as IAnnotationFeature;
                            ITextElement       ele      = anno_fea.Annotation as ITextElement;
                            //string text = ele.Text.Replace(System.Environment.NewLine, " ");
                            string      text     = ele.Text;
                            ITextSymbol sym      = ele.Symbol;
                            IFontDisp   font     = sym.Font;
                            double      symsize  = sym.Size;
                            string      fontname = font.Name;
                            decimal     fontsize = font.Size;
                            string.Format(@"a"":""");
                            JsonObject js_symbol = new JsonObject(
                                string.Format(@"{{""type"" : ""esriTS"",""color"": [255,255,255],""haloSize"" : 0,""haloColor"" : [255,255,255,0],""verticalAlignment"" : ""bottom"",""horizontalAlignment"" : ""center"",""size"": {0},""angle"": 0,""xoffset"": 0,""yoffset"": 0,""font"" : {{""family"" : ""{2}"",""size"" : {3},""style"" : ""normal"",""weight"" : ""normal"",""decoration"" : ""none""}},""text"":""{1}""}}", symsize, text, fontname, fontsize));
                            js_fea.AddJsonObject("symbol", js_symbol);
                            IArea pshp = fea_poi.Shape as IArea;
                            js_fea.AddJsonObject("geometry", Conversion.ToJsonObject(pshp.Centroid));
                        }
                        ls_features.Add(js_fea);
                        fea_poi = cur_poi.NextFeature();
                    }
                    response.AddArray("features", ls_features.ToArray());
                    client.StringSet(ns + grid_id.ToString(), response.ToJson());
                    ReleaseCOMObject(cur_poi);
                    grid_id++;
                    progressBar1.BeginInvoke((Action)(() =>
                    {
                        progressBar1.Increment(1);
                    }));
                }
            }
            MessageBox.Show("Build Cache Successfully!");
            this.button1.BeginInvoke((Action)(() =>
            {
                ListCaches();
                this.button1.Enabled = true;
            }));
        }
        /// <summary>
        /// operation solve trace
        /// </summary>
        /// <returns>solve trace</returns>
        public override JsonObject Solve()
        {
            try
            {
                if ((this.edgeFlags.Length == 0) && (this.junctionFlags.Length == 0))
                {
                    string message = "No input valid flags found";
                    if (this.flagNotFound.Count == 0)
                    {
                        throw new GeometricNetworkException(message);
                    }
                    else
                    {
                        JsonObject error = (new ObjectError(message)).ToJsonObject();
                        error.AddArray("flagsNotFound", Helper.GetListJsonObjects(this.flagNotFound));
                        if (this.barrierNotFound.Count > 0)
                        {
                            error.AddArray("barriersNotFound", Helper.GetListJsonObjects(this.barrierNotFound));
                        }

                        return(error);
                    }
                }

                ITraceFlowSolverGEN traceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
                INetSolver          netSolver       = traceFlowSolver as INetSolver;
                INetwork            network         = this.geometricNetwork.Network;
                netSolver.SourceNetwork = network;

                // flag origin
                this.SetFlagsOrigin(ref traceFlowSolver);

                // barrier
                this.SetBarriers(ref traceFlowSolver);

                // set disabled layers
                foreach (int i in this.DisableLayers)
                {
                    netSolver.DisableElementClass(i);
                }

                // set weight
                this.SetWeights(ref traceFlowSolver);

                if ((this.TraceSolverType != TraceSolverType.FindCircuits) && (this.TraceSolverType != TraceSolverType.FindCommonAncestors))
                {
                    // The TraceIndeterminateFlow property affects the trace results of trace solvers whose FlowMethod parameter is esriFMUpstream or esriFMDownstream
                    if ((this.FlowMethod == esriFlowMethod.esriFMDownstream) || (this.FlowMethod == esriFlowMethod.esriFMUpstream))
                    {
                        traceFlowSolver.TraceIndeterminateFlow = this.TraceIndeterminateFlow;
                    }
                }

                IEnumNetEID junctionEIDs = null;
                IEnumNetEID edgeEIDs     = null;
                object      totalCost;
                int         count;
                object[]    segmentCosts;

                JsonObject objectJson = new JsonObject();
                switch (this.TraceSolverType)
                {
                case TraceSolverType.FindAccumulation:
                    traceFlowSolver.FindAccumulation(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs, out totalCost);
                    objectJson.AddDouble("totalCost", (double)totalCost);
                    break;

                case TraceSolverType.FindCircuits:
                    traceFlowSolver.FindCircuits(this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindCommonAncestors:
                    traceFlowSolver.FindCommonAncestors(this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindFlowElements:
                    traceFlowSolver.FindFlowElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindFlowEndElements:
                    traceFlowSolver.FindFlowEndElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindFlowUnreachedElements:
                    traceFlowSolver.FindFlowUnreachedElements(this.FlowMethod, this.FlowElements, out junctionEIDs, out edgeEIDs);
                    break;

                case TraceSolverType.FindPath:
                    count = Math.Max(this.junctionFlags.Length, this.edgeFlags.Length);
                    if (count < 2)
                    {
                        throw new GeometricNetworkException("Edge or junction found < 2!");
                    }

                    --count;
                    segmentCosts = new object[count];
                    traceFlowSolver.FindPath(this.FlowMethod, this.ShortestPathObjFn, out junctionEIDs, out edgeEIDs, count, ref segmentCosts);
                    objectJson.AddArray("segmentCosts", segmentCosts);
                    break;

                case TraceSolverType.FindSource:
                    count        = this.junctionFlags.Length + this.edgeFlags.Length;
                    segmentCosts = new object[count];
                    traceFlowSolver.FindSource(this.FlowMethod, this.ShortestPathObjFn, out junctionEIDs, out edgeEIDs, count, ref segmentCosts);
                    objectJson.AddArray("segmentCosts", segmentCosts);
                    break;

                case TraceSolverType.FindLongest:
                    // get end junctions in upstream
                    IEnumNetEID junctionEIDsFindLongest = null;
                    IEnumNetEID edgeEIDsFindLongest     = null;
                    traceFlowSolver.FindFlowEndElements(esriFlowMethod.esriFMUpstream, esriFlowElements.esriFEJunctions, out junctionEIDsFindLongest, out edgeEIDsFindLongest);

                    int?   eidLongest       = null;
                    double eidLongestLenght = double.MinValue;

                    if (junctionEIDsFindLongest.Count > 0)
                    {
                        double eidLongestLenghtCurrent = double.NaN;
                        for (int i = 0; i < junctionEIDsFindLongest.Count; i++)
                        {
                            int         netEIDCurrent       = junctionEIDsFindLongest.Next();
                            object[]    segmentLenghts      = new object[1];
                            IEnumNetEID junctionEIDsLongest = null;
                            IEnumNetEID edgeEIDsLongest     = null;

                            INetFlag     netFlag = new JunctionFlagClass();
                            INetElements netElements = this.geometricNetwork.Network as INetElements;
                            int          featureClassID, featureID, subID;
                            netElements.QueryIDs(netEIDCurrent, esriElementType.esriETJunction, out featureClassID, out featureID, out subID);

                            netFlag.UserClassID = featureClassID;
                            netFlag.UserID      = featureID;
                            netFlag.UserSubID   = subID;

                            IJunctionFlag[] junctionFlags = new IJunctionFlag[] { this.junctionFlags[0], netFlag as IJunctionFlag };
                            traceFlowSolver.PutJunctionOrigins(ref junctionFlags);

                            traceFlowSolver.FindPath(esriFlowMethod.esriFMUpstream, esriShortestPathObjFn.esriSPObjFnMinMax, out junctionEIDsLongest, out edgeEIDsLongest, 1, ref segmentLenghts);
                            if (segmentLenghts[0] != null)
                            {
                                eidLongestLenghtCurrent = Convert.ToDouble(segmentLenghts[0]);
                                if (eidLongestLenghtCurrent > eidLongestLenght)
                                {
                                    eidLongestLenght = eidLongestLenghtCurrent;
                                    eidLongest       = netEIDCurrent;
                                    edgeEIDs         = edgeEIDsLongest;
                                    junctionEIDs     = junctionEIDsLongest;
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new GeometricNetworkException("Junction end not found!");
                    }

                    if (eidLongest.HasValue)
                    {
                        objectJson.AddDouble("totalCost", eidLongestLenght);
                    }
                    else
                    {
                        throw new GeometricNetworkException("EID longest not found!");
                    }

                    break;

                default:
                    throw new GeometricNetworkException("Trace solver type not found");
                }

                this.SetResults(ref objectJson, edgeEIDs, junctionEIDs);
                objectJson.AddArray("flagsNotFound", Helper.GetListJsonObjects(this.flagNotFound));
                objectJson.AddArray("barriersNotFound", Helper.GetListJsonObjects(this.barrierNotFound));
                return(objectJson);
            }
            catch (Exception e)
            {
                return((new ObjectError(e.Message)).ToJsonObject());
            }
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: 305120262/CachedLayerSystem
        /// <summary>
        /// Build Cache Backgroud worker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            
            int size = int.Parse(this.tbxSize.Text);
            IFeatureClass fc_poi = m_fcName.Open() as IFeatureClass;
            IGeoDataset ds_poi = fc_poi as IGeoDataset;
            int xmin = (int)Math.Floor(ds_poi.Extent.XMin);
            int ymin = (int)Math.Floor(ds_poi.Extent.YMin);
            int xmax = (int)Math.Ceiling(ds_poi.Extent.XMax);
            int ymax = (int)Math.Ceiling(ds_poi.Extent.YMax);

            List<JsonObject> ls_fields_cache = new List<JsonObject>();
            if(!(fc_poi.Extension is IAnnotationClassExtension))
            {
                for (int i = 0; i < fc_poi.Fields.FieldCount; i++)
                {
                    IField field = fc_poi.Fields.get_Field(i);
                    JsonObject js_f = new JsonObject();
                    js_f.AddString("name", field.Name);
                    js_f.AddString("type", Enum.GetName(typeof(esriFieldType), field.Type));
                    js_f.AddString("alias", field.AliasName);
                    if (field.Type == esriFieldType.esriFieldTypeString)
                    {
                        js_f.AddString("length", field.Length.ToString());
                    }
                    else
                    {
                        js_f.AddString("length", "");
                    }
                    ls_fields_cache.Add(js_f);
                }
            }
            
            IDatabase client = m_redis.GetDatabase();
            int grid_id=0;
            string ns = "poi:" + this.tbxCacheName.Text+":";
            for (int y = ymin; y <= ymax; y += size)
            {
                for (int x = xmin; x <= xmax; x += size)
                {                 
                    List<String> str_poi_grid = new List<String>();
                    List<JsonObject> ls_features = new List<JsonObject>();
                    //String str_response = client.StringGet(ns+"response");
                    //JsonObject response = new JsonObject(str_response);
                    JsonObject response = new JsonObject();
                    IEnvelope box = new EnvelopeClass();
                    box.XMin = x ;
                    box.YMin = y ;
                    box.XMax = x +size;
                    box.YMax = y +size;
                    ISpatialFilter filter_poi = new SpatialFilterClass();
                    filter_poi.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    filter_poi.Geometry = box;
                    filter_poi.SubFields = "*";
                    IFeatureCursor cur_poi = fc_poi.Search(filter_poi, true);
                    IFeature fea_poi = cur_poi.NextFeature();
                    while (fea_poi != null)
                    {
                        JsonObject js_fea = new JsonObject();
                        if (!(fea_poi is IAnnotationFeature))
                        {
                            JsonObject js_attributes = new JsonObject();
                            int i = 0;
                            foreach (JsonObject js_field in ls_fields_cache)
                            {
                                object value = fea_poi.get_Value(i);
                                string fieldtype;
                                js_field.TryGetString("type", out fieldtype);
                                string fieldname;
                                js_field.TryGetString("name", out fieldname);
                                #region
                                if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeString))
                                {
                                    js_attributes.AddString(fieldname, value.ToString());
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeOID))
                                {
                                    js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeInteger))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = 0;
                                    }
                                    js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeSmallInteger))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = 0;
                                    }
                                    js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeDouble))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = 0;
                                    }
                                    js_attributes.AddDouble(fieldname, double.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeDate))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = DateTime.MinValue;
                                    }
                                    js_attributes.AddDate(fieldname, DateTime.Parse(value.ToString()));
                                }
                                else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeSingle))
                                {
                                    if (value.ToString() == "")
                                    {
                                        value = 0;
                                    }
                                    js_attributes.AddBoolean(fieldname, bool.Parse(value.ToString()));
                                }
                                #endregion
                                i++;
                            }
                            js_fea.AddJsonObject("attributes", js_attributes);
                            js_fea.AddJsonObject("geometry", Conversion.ToJsonObject(fea_poi.Shape));
                        }
                        else
                        {
                            IAnnotationFeature anno_fea = fea_poi as IAnnotationFeature;
                            ITextElement ele = anno_fea.Annotation as ITextElement;
                            //string text = ele.Text.Replace(System.Environment.NewLine, " ");
                            string text = ele.Text;
                            ITextSymbol sym = ele.Symbol;
                            IFontDisp font = sym.Font;
                            double symsize = sym.Size;
                            string fontname = font.Name;
                            decimal fontsize = font.Size;
                            string.Format(@"a"":""");
                            JsonObject js_symbol = new JsonObject(
                            string.Format(@"{{""type"" : ""esriTS"",""color"": [255,255,255],""haloSize"" : 0,""haloColor"" : [255,255,255,0],""verticalAlignment"" : ""bottom"",""horizontalAlignment"" : ""center"",""size"": {0},""angle"": 0,""xoffset"": 0,""yoffset"": 0,""font"" : {{""family"" : ""{2}"",""size"" : {3},""style"" : ""normal"",""weight"" : ""normal"",""decoration"" : ""none""}},""text"":""{1}""}}",symsize,text,fontname,fontsize)); 
                            js_fea.AddJsonObject("symbol", js_symbol);
                            IArea pshp = fea_poi.Shape as IArea; 
                            js_fea.AddJsonObject("geometry", Conversion.ToJsonObject(pshp.Centroid));
                        }
                        ls_features.Add(js_fea);
                        fea_poi = cur_poi.NextFeature();
                    }
                    response.AddArray("features", ls_features.ToArray());
                    client.StringSet(ns+grid_id.ToString(), response.ToJson());
                    ReleaseCOMObject(cur_poi);
                    grid_id++;
                    progressBar1.BeginInvoke((Action)(() =>
                    {
                        progressBar1.Increment(1);
                    }));
                }
            }
            MessageBox.Show("Build Cache Successfully!");           
            this.button1.BeginInvoke((Action)(()=>
            {
                ListCaches();
                this.button1.Enabled = true;
            }));
        }