public AddPolygon ( IFeatureLayer featureLayer, IFeatureWorkspace featureworkspace, string dir ) : void | ||
featureLayer | IFeatureLayer | |
featureworkspace | IFeatureWorkspace | |
dir | string | |
리턴 | void |
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);
}
}
protected override void OnClick() { string straboPath = Environment.GetEnvironmentVariable(ArcStrabo2Extension.EnvironmentVariableSTRABO_HOME, EnvironmentVariableTarget.User); string tessPath = Environment.GetEnvironmentVariable(ArcStrabo2Extension.EnvironmentVariableTESS_DATA, EnvironmentVariableTarget.User); if (ArcStrabo2Extension.PathSet == false) { if (String.IsNullOrEmpty(straboPath) == true) { MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoStraboHome); return; } if (String.IsNullOrEmpty(tessPath) == true) { MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoTess_Data); return; } ////Initialize directories bool Initialize_straboPath_Correct = ArcStrabo2Extension.initialize_straboPath_directories(straboPath); if (Initialize_straboPath_Correct == false) { MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoStraboHomeWritePermission); return; } ArcStrabo2Extension.PathSet = true; } #region Text Recognition ////Save Positive and Negative Layer and making GeoJason File ComboBoxLayerSelector layerNameCombo = ComboBoxLayerSelector.GetLayerNameComboBox(); ////Select correct raster map layer RasterLayer rasterlayer = new RasterLayer(); rasterlayer = ((RasterLayer)layerNameCombo.GetSelectedLayer()); string input_data_source_directory; try { input_data_source_directory = rasterlayer.FilePath; } catch (Exception) { // Handle no input map error MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoInputMap, "Input Map Error", MessageBoxButtons.OK); return; } ////Select language from combo box in toolbar ComboBoxLanguageSelector languageNameCombo = ComboBoxLanguageSelector.GetLanguageNameComboBox(); string lng = languageNameCombo.Get_selected_language(); if (lng == null) { MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoInputLanguage, "Input Language Error", MessageBoxButtons.OK); return; } ////Set Log Directory Path Log.SetLogDir(ArcStrabo2Extension.Log_Path); Log.SetOutputDir(ArcStrabo2Extension.Log_Path); Log.WriteLine("MakingTextLabelGeoJsonFile Method Start SIMA"); IMap map = ArcMap.Document.FocusMap; ArcStraboObject arcStraboObject = new ArcStraboObject(); arcStraboObject.MakingTextLabelGeoJsonFile(ArcStrabo2Extension.Text_Result_Path); Log.WriteLine("MakingTextLabelGeoJsonFile Method Finish"); ////Run TextExtraction Layer from Strabo.core and load raster Layer Log.WriteLine("textLayerExtract Medthod Start SIMA"); arcStraboObject.textLayerExtract(input_data_source_directory, ArcStrabo2Extension.Text_Result_Path); Log.WriteLine("textLayerExtract Method Finish"); Log.WriteLine("AddRasterLayer Method Start SIMA"); arcStraboObject.AddRasterLayer(ArcStrabo2Extension.Text_Result_Path, ArcStrabo2Extension.TextLayerPNGFileName); Log.WriteLine("AddRasterLayer Method Finish"); ////Run TextIdentifier Method Log.WriteLine("textIndentification Method Start SIMA"); System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; ///// Attempting to create cancel feature window //DialogResult result = MessageBox.Show("Text Recognition is running.", "Application Running", MessageBoxButtons.OKCancel); //if (result == DialogResult.Cancel) //{ // return; //} //else if (result == DialogResult.OK) arcStraboObject.textIndentification(ArcStrabo2Extension.Text_Result_Path + "\\", ArcStrabo2Extension.Intermediate_Result_Path + "\\", ArcStrabo2Extension.TextLayerPNGFileName); System.Windows.Forms.Cursor.Current = Cursors.Default; Log.WriteLine("textIndentification Method Finish"); ////OCR Part Log.WriteLine("ExtractTextToGEOJSON Method Start SANJUALI"); System.Windows.Forms.Cursor.Current = Cursors.AppStarting; //// Select language from combo box in toolbar //ComboBoxLanguageSelector languageNameCombo = ComboBoxLanguageSelector.GetLanguageNameComboBox(); //string lng = languageNameCombo.Get_selected_language(); //if (lng == null) //{ // MessageBox.Show(ArcStrabo2Extension.ErrorMsgNoInputLanguage, "Input Language Error", MessageBoxButtons.OK); // return; //} Strabo.Core.OCR.WrapperTesseract language = new Strabo.Core.OCR.WrapperTesseract(tessPath, lng); /// Strabo.Core.OCR.WrapperTesseract language = new Strabo.Core.OCR.WrapperTesseract(tessPath); language.ExtractTextToGEOJSON(ArcStrabo2Extension.Intermediate_Result_Path,ArcStrabo2Extension.Text_Result_Path,ArcStrabo2Extension.TesseractResultsJSONFileName); Log.WriteLine("ExtractTextToGEOJSON Method Finish"); System.Windows.Forms.Cursor.Current = Cursors.Default; ////Add Polygon of OCR Layer Log.WriteLine("CreateFeatureClassWithFields Method Start SIMA"); IWorkspace workspace = arcStraboObject.CreateShapefileWorkspace(ArcStrabo2Extension.Text_Result_Path); IFeatureWorkspace featureworkspace = (IFeatureWorkspace)workspace; string tesseDataPath = ArcStrabo2Extension.Text_Result_Path + "\\" + ArcStrabo2Extension.TesseractResultsJSONFileName; IFeatureClass featureClass = arcStraboObject.CreateFeatureClassWithFields(ArcStrabo2Extension.TextLayerOCRShapefile, featureworkspace, tesseDataPath); IFeatureLayer featureLayer = arcStraboObject.CreateFeatureLayer(featureClass); Log.WriteLine("CreateFeatureClassWithFields Method Finish"); Log.WriteLine("AddPolygon Method Start"); arcStraboObject.AddPolygon(featureLayer, featureworkspace, tesseDataPath); Log.WriteLine("AddPolygon Method Finish"); Log.ArchiveLog(); MessageBox.Show("Text recognition finished!", "Done", MessageBoxButtons.OK); #endregion }