/// <summary> /// Add Feature class and its feilds /// </summary> /// <param name="featureClassName"></param> /// <param name="featureWorkspace"></param> /// <returns></returns> public IFeatureClass CreateFeatureClassWithFields(String featureClassName, IFeatureWorkspace featureWorkspace, string dir) { GeoJson geoJson = new GeoJson(); try { _featureInJSON = geoJson.readGeoJsonFile(dir); // Instantiate a feature class description to get the required fields. IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass(); IObjectClassDescription ocDescription = (IObjectClassDescription) fcDescription; IFields fields = ocDescription.RequiredFields; IFieldsEdit fieldsEdit = (IFieldsEdit)fields; for (int i = 0; i < 9; i++) { if (_featureInJSON.fields[i].name == "OBJECTID") continue; else addFeatureFeild(_featureInJSON.fields[i].name, _featureInJSON.fields[i].alias, (esriFieldType)Enum.Parse(typeof(esriFieldType), _featureInJSON.fields[i].type), fieldsEdit); } // Use IFieldChecker to create a validated fields collection. IFieldChecker fieldChecker = new FieldCheckerClass(); IEnumFieldError enumFieldError = null; IFields validatedFields = null; fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); // The enumFieldError enumerator can be inspected at this point to determine // which fields were modified during validation. // Create the feature class. IFeatureClass featureClass = featureWorkspace.CreateFeatureClass (featureClassName, validatedFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, ""); return featureClass; } catch (Exception e) { Log.WriteLine("CreateFeatureClassWithFields: " + e.Message); } return null; }
/// <summary> /// Read the GeoJason File and add new Polygongs to the vector layer /// the name of file should be newFile.json /// </summary> /// <param name="featureLayer"></param> /// <param name="featureworkspace"></param> public void AddPolygon(IFeatureLayer featureLayer, IFeatureWorkspace featureworkspace, string dir) { try { //Define vertices GeoJson geoJson = new GeoJson(); _featureInJSON = geoJson.readGeoJsonFile(dir); IMap map = ArcMap.Document.FocusMap; AddGraphicToMap(map); IWorkspaceEdit editWorkspace = featureworkspace as IWorkspaceEdit; editWorkspace.StartEditing(true); editWorkspace.StartEditOperation(); for (int j = 0; j < _featureInJSON.features.Count; j++) { IPoint pPoint1 = new ESRI.ArcGIS.Geometry.Point(); IPoint pPoint2 = new ESRI.ArcGIS.Geometry.Point(); IPoint pPoint3 = new ESRI.ArcGIS.Geometry.Point(); IPoint pPoint4 = new ESRI.ArcGIS.Geometry.Point(); pPoint1.PutCoords(_featureInJSON.features[j].geometry.rings[0, 0, 0], _featureInJSON.features[j].geometry.rings[0, 0, 1]); pPoint2.PutCoords(_featureInJSON.features[j].geometry.rings[0, 1, 0], _featureInJSON.features[j].geometry.rings[0, 1, 1]); pPoint3.PutCoords(_featureInJSON.features[j].geometry.rings[0, 2, 0], _featureInJSON.features[j].geometry.rings[0, 2, 1]); pPoint4.PutCoords(_featureInJSON.features[j].geometry.rings[0, 3, 0], _featureInJSON.features[j].geometry.rings[0, 3, 1]); IPointCollection pPolygon = new Polygon(); IPointCollection pPointCollection = pPolygon as IPointCollection; //Add the vertices of the polygon pPointCollection.AddPoints(1, ref pPoint1); pPointCollection.AddPoints(1, ref pPoint2); pPointCollection.AddPoints(1, ref pPoint3); pPointCollection.AddPoints(1, ref pPoint4); ((IPolygon)pPolygon).Close(); IFeature iFeature = featureLayer.FeatureClass.CreateFeature(); iFeature.Shape = (IPolygon)pPolygon; iFeature.Store(); //Feature cursor used to loop through all features in feature class, optionally a query filter can be used. int num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Char_count); iFeature.set_Value(num, _featureInJSON.features[j].attributes.Char_count.ToString()); num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Filename); iFeature.set_Value(num, _featureInJSON.features[j].attributes.Filename); //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Mass_centerX); iFeature.set_Value(8, _featureInJSON.features[j].attributes.Mass_centerX.ToString()); //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Mass_centerY); iFeature.set_Value(9, _featureInJSON.features[j].attributes.Mass_centerY.ToString()); //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.OBJECTID); //iFeature.set_Value(num, _featureInJSON.features[j].attributes.OBJECTID.ToString()); //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Orientation); iFeature.set_Value(4, _featureInJSON.features[j].attributes.OBJECTID.ToString()); //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Susp_char_count); iFeature.set_Value(7, _featureInJSON.features[j].attributes.Susp_char_count.ToString()); num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Susp_text); iFeature.set_Value(num, _featureInJSON.features[j].attributes.Susp_text.ToString()); num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Text); iFeature.set_Value(num, _featureInJSON.features[j].attributes.Text); iFeature.Store(); } IFeatureCursor fcCursor = featureLayer.FeatureClass.Update(null, true); //Stop the operation and provide a name to add to the operation stack. editWorkspace.StartEditOperation(); //Stop editing and save the edits. editWorkspace.StopEditing(true); map.AddLayer(featureLayer); } catch (Exception e) { Log.WriteLine("AddPolygon: " + e.Message); } }
private void fillImageList(string path, List<Bitmap> imgList, Image<Bgr, Byte> srcImage) { FeatureInJSON _featureInJSON; GeoJson geoJson = new GeoJson(); try { if (!File.Exists(path)) return; _featureInJSON = geoJson.readGeoJsonFile(path); for (int j = 0; j < _featureInJSON.features.Count; j++) { double x1, x2, y1, y2; x1 = _featureInJSON.features[j].geometry.rings[0, 0, 0]; y1 = _featureInJSON.features[j].geometry.rings[0, 0, 1]; x2 = _featureInJSON.features[j].geometry.rings[0, 1, 0]; y2 = _featureInJSON.features[j].geometry.rings[0, 2, 1]; Rectangle rec = new Rectangle(int.Parse(Math.Round(x1).ToString()), int.Parse((Math.Round(y1 * -1)).ToString()), int.Parse(Math.Round((x2 - x1)).ToString()), int.Parse(Math.Round((y1 - y2)).ToString())); // Image<Bgr, Byte> test = srcImage.GetSubRect(rec); Bitmap img = srcImage.Bitmap; if (rec.X < 0 || rec.X > srcImage.Width || rec.Y < 0 || rec.Y > srcImage.Height) { System.Windows.Forms.MessageBox.Show("Text recognition labels are out of bound! please check and put them within Image"); return; } Bitmap cropedImage = img.Clone(rec, img.PixelFormat); cropedImage.Save(CreateDirectory(path, "Data") + "\\img" + j.ToString()); imgList.Add(cropedImage); } } catch (Exception e) { Log.WriteLine("fillImageList: " + e.Message); } }
private void fillSymbolList(List<Bitmap> imgList, Image<Bgr, Byte> srcImage) { FeatureInJSON _featureInJSON; GeoJson geoJson = new GeoJson(); try { if (!File.Exists(_rasterInfo.rasterData + "\\PositiveLayerInfo.json")) return; _featureInJSON = geoJson.readGeoJsonFile(_rasterInfo.rasterData + "\\PositiveLayerInfo.json"); for (int j = 0; j < _featureInJSON.features.Count; j++) { double x1, x2, y1, y2; Rectangle rec; x1 = _featureInJSON.features[j].geometry.rings[0, 0, 0]; y1 = _featureInJSON.features[j].geometry.rings[0, 0, 1]; x2 = _featureInJSON.features[j].geometry.rings[0, 1, 0]; y2 = _featureInJSON.features[j].geometry.rings[0, 2, 1]; if (_rasterInfo.rasterType != "Unknown") { double pixelX1, pixelY1, pixelX2, pixelY2; ////////////////////geo Spatial Project Change///////////////////// GetXY(x1, y1, out pixelX1, out pixelY1); GetXY(x2, y2, out pixelX2, out pixelY2); double r1 = pixelY2 - pixelY1; double r2 = pixelX2 - pixelX1; rec = new Rectangle((int.Parse(Math.Round(pixelX1).ToString())), int.Parse((Math.Round(pixelY1)).ToString()), int.Parse(Math.Round(Math.Abs(r2)).ToString()), int.Parse(Math.Round(Math.Abs(r1)).ToString())); } else { rec = new Rectangle((int.Parse(Math.Round(Math.Abs(x1)).ToString())), int.Parse((Math.Round(Math.Abs(y1))).ToString()), int.Parse(Math.Round(Math.Abs(x1 - x2)).ToString()), int.Parse(Math.Round(Math.Abs(y1 - y2)).ToString())); } // Image<Bgr, Byte> test = srcImage.GetSubRect(rec); Bitmap img = srcImage.Bitmap; Bitmap cropedImage = img.Clone(rec, img.PixelFormat); if (!System.IO.Directory.Exists(_rasterInfo.rasterIn)) System.IO.Directory.CreateDirectory(_rasterInfo.rasterIn); Bitmap resizedImage = new Bitmap(cropedImage, cropedImage.Width, cropedImage.Height); resizedImage.Save(_rasterInfo.rasterIn + "\\element.png"); imgList.Add(cropedImage); } } catch (Exception e) { Log.WriteLine("fillImageList: " + e.Message); } }
private void fillImageList(string path, List<Bitmap> imgList, Image<Bgr, Byte> srcImage) { FeatureInJSON _featureInJSON; GeoJson geoJson = new GeoJson(); try { if (!File.Exists(path)) return; _featureInJSON = geoJson.readGeoJsonFile(path); for (int j = 0; j < _featureInJSON.features.Count; j++) { double x1, x2, y1, y2; x1 = _featureInJSON.features[j].geometry.rings[0, 0, 0]; y1 = _featureInJSON.features[j].geometry.rings[0, 0, 1]; x2 = _featureInJSON.features[j].geometry.rings[0, 1, 0]; y2 = _featureInJSON.features[j].geometry.rings[0, 2, 1]; Rectangle rec = new Rectangle(int.Parse(Math.Round(x1).ToString()), int.Parse((Math.Round(y1 * -1)).ToString()), int.Parse(Math.Round((x2 - x1)).ToString()), int.Parse(Math.Round((y1 - y2)).ToString())); //Image<Bgr, Byte> test = srcImage.GetSubRect(rec); Bitmap img = srcImage.Bitmap; Bitmap cropedImage = img.Clone(rec, img.PixelFormat); //cropedImage.Save(CreateDirectory(path, "Data") + "\\img" + j.ToString()); imgList.Add(cropedImage); } } catch (Exception e) { Log.WriteLine("fillImageList: " + e.Message); } }