/// <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> /// 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; })); }