public void MakingSymbolGeoJsonFile() { /////////////////////////////////////////////////////////////// //Setting current Map to access Layers, Feature Class and Features //build string builder to write on the ImageResultfile /////////////////////////////////////////////////////////////// string path = ""; IMap map = ArcMap.Document.FocusMap; //GeoJson geoJson; IEnumLayer enumLayer = map.get_Layers(null, true); ILayer layer = enumLayer.Next(); //((IDataset)layer).Workspace. IFeatureLayer featureLayer; IFeature iFeature; try { while (layer != null) { if (layer.Name == "SymbolPositiveLabel") { GeoJson geoJson = new GeoJson(); geoJson.featureInJson = new FeatureInJSON(); geoJson.featureInJson.displayFieldName = layer.Name; geoJson.featureInJson.fieldAliases = new FieldAliases(); //////////////////////////Set Alias Feature of the Layer//////////////////// geoJson.featureInJson.fieldAliases.Mass_centerX = "Mass_centerX"; geoJson.featureInJson.fieldAliases.Mass_centerY = "Mass_centerY"; geoJson.featureInJson.fieldAliases.OBJECTID = "OBJECTID"; geoJson.featureInJson.fieldAliases.Orientation = "Orientation"; geoJson.featureInJson.fieldAliases.Susp_char_count = "Susp_char_count"; geoJson.featureInJson.fieldAliases.Susp_text = "Susp_text"; geoJson.featureInJson.fieldAliases.Text = "Text"; geoJson.featureInJson.fieldAliases.Char_count = "Char_count"; geoJson.featureInJson.fieldAliases.Filename = "Filename"; //////////////////////Set Fields of the current Layer/////////////////////// geoJson.featureInJson.fields = new Field_info[9]; setGeoJASONFeilds("OBJECTID", esriFieldType.esriFieldTypeOID, geoJson.featureInJson.fields[0]); setGeoJASONFeilds("Text", esriFieldType.esriFieldTypeString, geoJson.featureInJson.fields[1]); setGeoJASONFeilds("Char_count", esriFieldType.esriFieldTypeInteger, geoJson.featureInJson.fields[2]); setGeoJASONFeilds("Orientation", esriFieldType.esriFieldTypeDouble, geoJson.featureInJson.fields[3]); setGeoJASONFeilds("Filename", esriFieldType.esriFieldTypeString, geoJson.featureInJson.fields[4]); setGeoJASONFeilds("Susp_text", esriFieldType.esriFieldTypeString, geoJson.featureInJson.fields[5]); setGeoJASONFeilds("Susp_char_count", esriFieldType.esriFieldTypeInteger, geoJson.featureInJson.fields[6]); setGeoJASONFeilds("Mass_centerX", esriFieldType.esriFieldTypeDouble, geoJson.featureInJson.fields[7]); setGeoJASONFeilds("Mass_centerY", esriFieldType.esriFieldTypeDouble, geoJson.featureInJson.fields[8]); path = _rasterInfo.rasterData + "\\PositiveLayerInfo.json";//@"C:\Emgu\emgucv-windows-universal-cuda 2.9.0.1922\Emgu.CV.Example\Strabo_Map_Processing\Hollywood\Data\PositiveLayerInfo.json"; // featureLayer = (IFeatureLayer)layer; int count = featureLayer.FeatureClass.FeatureCount(null); for (int j = 1; j <= count; j++) { iFeature = featureLayer.FeatureClass.GetFeature(j); geoJson.featureInJson.features.Add(new Features()); int i = j - 1; geoJson.featureInJson.features[i].attributes = new Attributes(); geoJson.featureInJson.features[i].attributes.OBJECTID = int.Parse(iFeature.get_Value(0).ToString()); geoJson.featureInJson.features[i].geometry = new Strabo.Core.OCR.Geometry(); geoJson.featureInJson.features[i].geometry.rings[0, 0, 0] = iFeature.Extent.UpperLeft.X; geoJson.featureInJson.features[i].geometry.rings[0, 0, 1] = iFeature.Extent.UpperLeft.Y; geoJson.featureInJson.features[i].geometry.rings[0, 1, 0] = iFeature.Extent.UpperRight.X; geoJson.featureInJson.features[i].geometry.rings[0, 1, 1] = iFeature.Extent.UpperRight.Y; geoJson.featureInJson.features[i].geometry.rings[0, 2, 0] = iFeature.Extent.LowerRight.X; geoJson.featureInJson.features[i].geometry.rings[0, 2, 1] = iFeature.Extent.LowerRight.Y; geoJson.featureInJson.features[i].geometry.rings[0, 3, 0] = iFeature.Extent.LowerLeft.X; geoJson.featureInJson.features[i].geometry.rings[0, 3, 1] = iFeature.Extent.LowerLeft.Y; geoJson.featureInJson.features[i].geometry.rings[0, 4, 0] = iFeature.Extent.UpperLeft.X; geoJson.featureInJson.features[i].geometry.rings[0, 4, 1] = iFeature.Extent.UpperLeft.Y; if (iFeature.Extent.UpperLeft.Y < 0 && _rasterInfo.ratserNegative > 0) _rasterInfo.ratserNegative = -1; } geoJson.writeJsonFile(path); } layer = enumLayer.Next(); } } catch (Exception e) { Log.WriteLine(e.Message); } }
/// <summary> /// access to the positive and negative layer and save them on the GeoJson File /// </summary> public void MakingTextLabelGeoJsonFile(string dir) { /////////////////////////////////////////////////////////////// //Setting current Map to access Layers, Feature Class and Features //build string builder to write on the ImageResultfile /////////////////////////////////////////////////////////////// string path = ""; IMap map = ArcMap.Document.FocusMap; //GeoJson geoJson; IEnumLayer enumLayer = map.get_Layers(null, true); ILayer layer = enumLayer.Next(); //((IDataset)layer).Workspace. IFeatureLayer featureLayer; try { while (layer != null) { if (layer.Name == ArcStrabo10Extension.TextPositiveLabelLayerName || layer.Name == ArcStrabo10Extension.TextNegtiveLabelLayerName) { GeoJson geoJson = new GeoJson(); geoJson.featureInJson = new FeatureInJSON(); geoJson.featureInJson.displayFieldName = layer.Name; geoJson.featureInJson.fieldAliases = new FieldAliases(); //////////////////////////Set Alias Feature of the Layer//////////////////// geoJson.featureInJson.fieldAliases.Mass_centerX = "Mass_centerX"; geoJson.featureInJson.fieldAliases.Mass_centerY = "Mass_centerY"; geoJson.featureInJson.fieldAliases.OBJECTID = "OBJECTID"; geoJson.featureInJson.fieldAliases.Orientation = "Orientation"; geoJson.featureInJson.fieldAliases.Susp_char_count = "Susp_char_count"; geoJson.featureInJson.fieldAliases.Susp_text = "Susp_text"; geoJson.featureInJson.fieldAliases.Text = "Text"; geoJson.featureInJson.fieldAliases.Char_count = "Char_count"; geoJson.featureInJson.fieldAliases.Filename = "Filename"; //////////////////////Set Fields of the current Layer/////////////////////// geoJson.featureInJson.fields = new Field_info[9]; setGeoJASONFeilds("OBJECTID", esriFieldType.esriFieldTypeOID, geoJson.featureInJson.fields[0]); setGeoJASONFeilds("Text", esriFieldType.esriFieldTypeString, geoJson.featureInJson.fields[1]); setGeoJASONFeilds("Char_count", esriFieldType.esriFieldTypeInteger, geoJson.featureInJson.fields[2]); setGeoJASONFeilds("Orientation", esriFieldType.esriFieldTypeDouble, geoJson.featureInJson.fields[3]); setGeoJASONFeilds("Filename", esriFieldType.esriFieldTypeString, geoJson.featureInJson.fields[4]); setGeoJASONFeilds("Susp_text", esriFieldType.esriFieldTypeString, geoJson.featureInJson.fields[5]); setGeoJASONFeilds("Susp_char_count", esriFieldType.esriFieldTypeInteger, geoJson.featureInJson.fields[6]); setGeoJASONFeilds("Mass_centerX", esriFieldType.esriFieldTypeDouble, geoJson.featureInJson.fields[7]); setGeoJASONFeilds("Mass_centerY", esriFieldType.esriFieldTypeDouble, geoJson.featureInJson.fields[8]); //************************GeoProjectChange***SIIIIIIMA*********************************************************** if (layer.Name == ArcStrabo10Extension.TextPositiveLabelLayerName) path = dir + "\\" + ArcStrabo10Extension.TextPositiveLabelLayerJSONFileName; else if (layer.Name == ArcStrabo10Extension.TextNegtiveLabelLayerName) path = dir + "\\" + ArcStrabo10Extension.TextNegtiveLabelLayerJSONFileName; featureLayer = (IFeatureLayer)layer; int count = featureLayer.FeatureClass.FeatureCount(null); //for (int j = 1; j <= count; j++) //{ IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(null, false);// (null, enableRecycling); IFeature iFeature = featureCursor.NextFeature(); int i = 0; while (iFeature != null) { geoJson.featureInJson.features.Add(new Features()); geoJson.featureInJson.features[i].attributes = new Attributes(); geoJson.featureInJson.features[i].attributes.OBJECTID = int.Parse(iFeature.get_Value(0).ToString()); geoJson.featureInJson.features[i].geometry = new Strabo.Core.OCR.Geometry(); geoJson.featureInJson.features[i].geometry.rings[0, 0, 0] = iFeature.Extent.UpperLeft.X; geoJson.featureInJson.features[i].geometry.rings[0, 0, 1] = iFeature.Extent.UpperLeft.Y; geoJson.featureInJson.features[i].geometry.rings[0, 1, 0] = iFeature.Extent.UpperRight.X; geoJson.featureInJson.features[i].geometry.rings[0, 1, 1] = iFeature.Extent.UpperRight.Y; geoJson.featureInJson.features[i].geometry.rings[0, 2, 0] = iFeature.Extent.LowerRight.X; geoJson.featureInJson.features[i].geometry.rings[0, 2, 1] = iFeature.Extent.LowerRight.Y; geoJson.featureInJson.features[i].geometry.rings[0, 3, 0] = iFeature.Extent.LowerLeft.X; geoJson.featureInJson.features[i].geometry.rings[0, 3, 1] = iFeature.Extent.LowerLeft.Y; geoJson.featureInJson.features[i].geometry.rings[0, 4, 0] = iFeature.Extent.UpperLeft.X; geoJson.featureInJson.features[i].geometry.rings[0, 4, 1] = iFeature.Extent.UpperLeft.Y; iFeature = featureCursor.NextFeature(); i++; } geoJson.writeJsonFile(path); } layer = enumLayer.Next(); } } catch (Exception e) { Log.WriteLine(e.Message); } }
/// <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; }
public IFeatureClass CreateFeatureClassWithFieldsGeoRef(String featureClassName, IFeatureWorkspace featureWorkspace) { GeoJson geoJson = new GeoJson(); try { // 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; addFeatureFeild("URI", "URI", esriFieldType.esriFieldTypeString, 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 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; 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 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); } }
/// <summary> /// Extracts text from images using tesseract and creates a GEOJSON file with all the features /// </summary> /// <param name="dirPath">This is the path where all the image files will be present</param> public void ExtractTextToGEOJSON(string inputPath, string outputPath, string TesseractResultsJSONFileName) { string[] filePaths = Directory.GetFiles(inputPath, "*.png"); if (filePaths.Length == 0) return; int noOfFiles = filePaths.Length; String[] text = new String[noOfFiles]; float[] textCost = new float[noOfFiles]; Bgr drawColor = new Bgr(Color.Gray); int[] imageIds = new int[noOfFiles]; try { Console.WriteLine("Tessearct in progress..."); for (int i = 0; i < noOfFiles; i++) { string filename = Path.GetFileName(filePaths[i]); String[] splitTokens = filename.Split('_'); if (splitTokens.Length != 11) continue; Image<Bgr, Byte> image = new Image<Bgr, byte>(filePaths[i]); using (Image<Gray, byte> gray = image.Convert<Gray, Byte>()) { int index = 0; _ocr.Recognize(gray); int charCount = 0; textCost[i] = 0; Tesseract.Charactor[] recog_char = _ocr.GetCharactors(); while (charCount < recog_char.Length) { text[i] += recog_char[charCount].Text; textCost[i] += recog_char[charCount].Cost; charCount++; } imageIds[i] = int.Parse(filename.Split('_')[0]); index = Array.IndexOf(imageIds, imageIds[i]); if (index != -1 && index != i) { if (textCost[index] < textCost[i]) imageIds[i] = -1; else imageIds[index] = -1; } } } } catch (Exception exception) { //MessageBox.Show(exception.Message); Log.WriteLine(exception.Message); Log.WriteLine(exception.ToString()); throw (exception); } try { FeatureInJSON jsonFeatures = new FeatureInJSON(); jsonFeatures.displayFieldName = ""; jsonFeatures.geometryType = "esriGeometryPolygon"; jsonFeatures.fieldAliases.OBJECTID = "OBJECTID"; jsonFeatures.fieldAliases.Filename = "Filename"; jsonFeatures.fieldAliases.Orientation = "Orientation"; jsonFeatures.fieldAliases.Text = "Text"; jsonFeatures.fieldAliases.Susp_char_count = "Susp_char_count"; jsonFeatures.fieldAliases.Susp_text = "Susp_text"; jsonFeatures.fieldAliases.Mass_centerX = "Mass_centerX"; jsonFeatures.fieldAliases.Mass_centerY = "Mass_centerY"; jsonFeatures.fieldAliases.Char_count = "Char_count"; jsonFeatures.fieldAliases.DetectionCost = "DetectionCost"; jsonFeatures.spatialReference.latestWkid = 0; jsonFeatures.spatialReference.wkid = 0; jsonFeatures.fields[0].name = "OBJECTID"; jsonFeatures.fields[0].type = "esriFieldTypeOID"; jsonFeatures.fields[0].alias = "OBJECTID"; jsonFeatures.fields[0].length = 0; jsonFeatures.fields[1].name = "Text"; jsonFeatures.fields[1].type = "esriFieldTypeString"; jsonFeatures.fields[1].alias = "Text"; jsonFeatures.fields[1].length = 80; jsonFeatures.fields[2].name = "Char_count"; jsonFeatures.fields[2].type = "esriFieldTypeInteger"; jsonFeatures.fields[2].alias = "Char_count"; jsonFeatures.fields[2].length = 0; jsonFeatures.fields[3].name = "Orientation"; jsonFeatures.fields[3].type = "esriFieldTypeDouble"; jsonFeatures.fields[3].alias = "Orientation"; jsonFeatures.fields[3].length = 0; jsonFeatures.fields[4].name = "Filename"; jsonFeatures.fields[4].type = "esriFieldTypeString"; jsonFeatures.fields[4].alias = "Filename"; jsonFeatures.fields[4].length = 80; jsonFeatures.fields[5].name = "Susp_text"; jsonFeatures.fields[5].type = "esriFieldTypeString"; jsonFeatures.fields[5].alias = "Susp_text"; jsonFeatures.fields[5].length = 80; jsonFeatures.fields[6].name = "Susp_char_count"; jsonFeatures.fields[6].type = "esriFieldTypeInteger"; jsonFeatures.fields[6].alias = "Susp_char_count"; jsonFeatures.fields[6].length = 0; jsonFeatures.fields[7].name = "Mass_centerX"; jsonFeatures.fields[7].type = "esriFieldTypeDouble"; jsonFeatures.fields[7].alias = "Mass_centerX"; jsonFeatures.fields[7].length = 0; jsonFeatures.fields[8].name = "Mass_centerY"; jsonFeatures.fields[8].type = "esriFieldTypeDouble"; jsonFeatures.fields[8].alias = "Mass_centerY"; jsonFeatures.fields[8].length = 0; jsonFeatures.fields[9].name = "DetectionCost"; jsonFeatures.fields[9].type = "esriFieldTypeDouble"; jsonFeatures.fields[9].alias = "DetectionCost"; jsonFeatures.fields[9].length = 0; Array filesSearchArray = (Array)filePaths; Console.WriteLine("Converting to JSON..."); for (int i = 0; i < noOfFiles; i++) { if (imageIds[i] == -1 || textCost[i] == 0 || filePaths[i] == "") continue; char[] separator = new char[] { '_', '.' }; string filename = Path.GetFileName(filePaths[i]); String[] token = filename.Split(separator, StringSplitOptions.RemoveEmptyEntries); /* Regular expression to match non-word characters more than 3 in the text \p{L} matches any kind of letter from any langauge \p{Nd} matches a digit zero through nine in any script except ideographic scripts*/ Regex nonWords = new Regex("[^\\p{L}\\p{Nd}]{3}[^\\p{L}\\p{Nd}]+"); text[i] = nonWords.Replace(text[i], ""); if (text[i].Contains("1 1 1")) // dashed lines continue; if(alphnumericratio(text[i])==false) continue; Features ftr = new Features(); ftr.attributes.OBJECTID = Convert.ToInt16(token[0]); ftr.attributes.Text = text[i]; ftr.attributes.Char_count = Convert.ToInt16(token[2]); ftr.attributes.Orientation = Convert.ToInt16(token[6]); ftr.attributes.Filename = filename; ftr.attributes.Susp_char_count = 0; ftr.attributes.Susp_text = ""; ftr.attributes.Mass_centerX = Convert.ToInt16(token[3]); ftr.attributes.Mass_centerY = Convert.ToInt16(token[4]); ftr.attributes.DetectionCost = textCost[i]; int x = Convert.ToInt16(token[7]); int y = Convert.ToInt16(token[8]); int w = Convert.ToInt16(token[9]); int h = Convert.ToInt16(token[10]); ftr.geometry.rings[0, 0, 0] = x; ftr.geometry.rings[0, 0, 1] = -y; ftr.geometry.rings[0, 1, 0] = x + w; ftr.geometry.rings[0, 1, 1] = -y; ftr.geometry.rings[0, 2, 0] = x + w; ftr.geometry.rings[0, 2, 1] = -y - h; ftr.geometry.rings[0, 3, 0] = x; ftr.geometry.rings[0, 3, 1] = -y - h; ftr.geometry.rings[0, 4, 0] = x; ftr.geometry.rings[0, 4, 1] = -y; jsonFeatures.features.Add(ftr); GeoJson geoJson = new GeoJson(); geoJson.featureInJson = jsonFeatures; geoJson.writeJsonFile(outputPath + "\\" + TesseractResultsJSONFileName); } } catch (Exception exception) { //MessageBox.Show(exception.Message); Log.WriteLine(exception.Message); Log.WriteLine(exception.ToString()); throw (exception); } }