public GradePartition(IFeatureClass feacls,string divideField,double[] interval) { _feacls = feacls; _divideFiled = divideField; _isDivideOnInterval = true; _interval = interval; }
public QAExceptionStorage(IWorkspace isdutWorkspace, string schemaOwner, string operationalDSName) { if (isdutWorkspace == null) throw new ArgumentNullException("isdutWorkspace", "Cannot pass null workspace to QAExceptionStorage"); // Locate the ISDUT.ISDUT_DATA_EXCEPTION_POINTS featureclass in the workspace IFeatureClass theFC = null; string theFCName = ""; try { theFCName = FEATURECLASS_NAME; theFC = ((IFeatureWorkspace)isdutWorkspace).OpenFeatureClass(theFCName); } catch (Exception) {} if (theFC == null) throw new ErrorStorageException("isdutWorkspace does not contain a featureclass named '" + theFCName + "'", null); // Check the featureclass definition string theMessage = this.FeatureClassSchemaCheck(theFC); if (theMessage != null && theMessage.Length > 0) { throw new ErrorStorageException(theMessage, null); } this._operationalDSName = operationalDSName; this._exceptionFC = theFC; }
protected override void OnActivate() { //get the cadastral editor and target fabric m_pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); m_pCadFab = m_pCadEd.CadastralFabric; if (m_pCadFab == null) { MessageBox.Show("No target fabric found. Please add a fabric to the map start editing, and try again."); return; } m_pFabricLines = (IFeatureClass)m_pCadFab.get_CadastralTable(esriCadastralFabricTable.esriCFTLines); m_editor.CurrentTask = null; m_edSketch = m_editor as IEditSketch3; m_edSketch.GeometryType = esriGeometryType.esriGeometryPolyline; m_csc = new TraceConstructorClass(); m_csc.Initialize(m_editor); m_edSketch.ShapeConstructor = m_csc; m_csc.Activate(); // Setup events m_editEvents.OnSketchModified += OnSketchModified; m_editEvents5.OnShapeConstructorChanged += OnShapeConstructorChanged; m_editEvents.OnSketchFinished += OnSketchFinished; }
public Dictionary<string,object> FindValue(IFeatureClass pFeatureClass, string keyName, string targetName) { //int keyFieldIndex = pFeatureClass.Fields.FindField(keyField); //int targetFieldIndex = pFeatureClass.Fields.FindField(targetField); //IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); //IFeature pFeature; //while ((pFeature = pFeatureCursor.NextFeature()) != null) //{ // if (pFeature.Value[keyFieldIndex].ToString() == keyValue) break; //} //Marshal.ReleaseComObject(pFeatureCursor); //return pFeature == null ? null : pFeature.Value[targetFieldIndex]; int keyFieldIndex = pFeatureClass.Fields.FindField(keyName); int targetFieldIndex = pFeatureClass.Fields.FindField(targetName); Dictionary<string,object> dic=new Dictionary<string, object>(pFeatureClass.FeatureCount(null)); IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); IFeature pFeature; while ((pFeature = pFeatureCursor.NextFeature()) != null) { if (!dic.ContainsKey(pFeature.Value[keyFieldIndex].ToString())) { dic.Add(pFeature.Value[keyFieldIndex].ToString(), pFeature.Value[targetFieldIndex]); } } Marshal.ReleaseComObject(pFeatureCursor); return dic; }
public IFeatureClass Intsect(IFeatureClass _pFtClass, IFeatureClass _pFtOverlay, string _FilePath, string _pFileName) { IFeatureClassName pOutPut = new FeatureClassNameClass(); pOutPut.ShapeType = _pFtClass.ShapeType; pOutPut.ShapeFieldName = _pFtClass.ShapeFieldName; pOutPut.FeatureType = esriFeatureType.esriFTSimple; IWorkspaceName pWsN = new WorkspaceNameClass(); pWsN.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory"; pWsN.PathName = _FilePath; IDatasetName pDatasetName = pOutPut as IDatasetName; pDatasetName.Name = _pFileName; pDatasetName.WorkspaceName = pWsN; IBasicGeoprocessor pBasicGeo = new BasicGeoprocessorClass(); IFeatureClass pFeatureClass = pBasicGeo.Intersect(_pFtClass as ITable, false, _pFtOverlay as ITable, false, 0.1, pOutPut); return pFeatureClass; }
/// <summary> /// 转换 /// </summary> /// <param name="pFeatureClass">要素类</param> /// <param name="fieldName">栅格采用的字段</param> /// <param name="rasterWorkSpace">输出栅格的工作空间</param> /// <param name="newRasterName">新的栅格名称</param> public void Convert(IFeatureClass pFeatureClass, string fieldName, string rasterWorkSpace, string newRasterName) { FileHelper.DeleteFile(rasterWorkSpace, newRasterName, ".tif", ".tfw",".tif.aux"); IFeatureClassDescriptor featureClassDescriptor = new FeatureClassDescriptorClass(); featureClassDescriptor.Create(pFeatureClass, null, fieldName); IGeoDataset geoDataset = (IGeoDataset)featureClassDescriptor; IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass(); IWorkspace workspace = workspaceFactory.OpenFromFile(rasterWorkSpace, 0); IConversionOp conversionOp = new RasterConversionOpClass(); IRasterAnalysisEnvironment rasterAnalysisEnvironment = (IRasterAnalysisEnvironment)conversionOp; rasterAnalysisEnvironment.OutWorkspace = workspace; //set cell size rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _cellSize); //set output extent object objectMissing = Type.Missing; rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _extentEnvelope, ref objectMissing); //set output spatial reference rasterAnalysisEnvironment.OutSpatialReference = ((IGeoDataset)pFeatureClass).SpatialReference; //convertion conversionOp.ToRasterDataset(geoDataset, _rasterType, workspace, newRasterName); }
/// <summary> /// 获得字段唯一值 /// </summary> public List<object> GetDistinctValue(IFeatureClass FC, string FieldName) { if (FC.Fields.FindField(FieldName) < 0) return null; try { List<object> DistinctValue = new List<object>(); IDataset Dataset = (IDataset)FC; IFeatureWorkspace FWS = (IFeatureWorkspace)Dataset.Workspace; IQueryDef QueryDef = FWS.CreateQueryDef(); QueryDef.Tables = Dataset.Name; QueryDef.SubFields = "DISTINCT(" + FieldName + ")"; ICursor Cursor = QueryDef.Evaluate(); IRow Row = Cursor.NextRow(); while (Row != null) { object o = Row.get_Value(0); DistinctValue.Add(o); Row = Cursor.NextRow(); } return DistinctValue; } catch { return null; } }
public ZFeatureClass(IFeatureClass featureClass) : base(featureClass as IDataset) { this.Subtypes = new ObservableCollection<ZSubtype>(); this.Fields = new ObservableCollection<ZField>(); this.Id = featureClass.FeatureClassID; ISubtypes subtypes = (ISubtypes)featureClass; if (subtypes.HasSubtype) { IEnumSubtype enumSubtype = subtypes.Subtypes; int code; string subtypeName = enumSubtype.Next(out code); while (!string.IsNullOrEmpty(subtypeName)) { this.Subtypes.Add(new ZSubtype(this, code, subtypeName)); subtypeName = enumSubtype.Next(out code); } } else { this.Subtypes.Add(new ZDefaultSubtype(this)); } IFields fields = featureClass.Fields; for (int i = 0; i < fields.FieldCount; i++) { IField field = fields.get_Field(i); this.Fields.Add(new ZField(this, field)); } }
public dataPrepAdjustAccuracyAssessment(IFeatureClass ProjectArea, IFeatureClass Map, string originalAccuracyAssessmentModel, string adjustedAccuracyAssessmentModel) { projectArea = ProjectArea; ftrMap = Map; oModel = originalAccuracyAssessmentModel; aModel = adjustedAccuracyAssessmentModel; }
public static void BufferAnalysis(IFeatureClass feacls,string dist) { IGeoProcessor2 gp = new GeoProcessorClass(); gp.OverwriteOutput = true; IGeoProcessorResult result = new GeoProcessorResultClass(); //gp.SetEnvironmentValue("workspace", @"e:\data"); IVariantArray vararr = new VarArrayClass(); object sev = null; try { vararr.Add(feacls); vararr.Add(@"e:\data\wwwwwww.shp"); vararr.Add(dist); result = gp.Execute("Buffer_analysis", vararr, null); while (result.Status == esriJobStatus.esriJobExecuting) Thread.Sleep(1000); MessageBox.Show(gp.GetMessages(ref sev)); } catch (System.Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(gp.GetMessages(ref sev)); } }
public static void LoadListView(IFeatureClass pFC, ListView listView1) { try { listView1.Columns.Clear(); //添加一个空 ColumnHeader columnHeader = new ColumnHeader(); listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { columnHeader }); columnHeader.Text = ""; for (int i = 0; i < pFC.Fields.FieldCount; i++) { ColumnHeader columnHeader1 = new ColumnHeader(); listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { columnHeader1 }); IFields pFields = pFC.Fields; IField pField = pFields.get_Field(i); columnHeader1.Text = pField.AliasName; } } catch (Exception ex) { } }
/// <summary> /// Converts feature class to a recordset. /// </summary> /// <param name="fc">The fc.</param> /// <returns></returns> public IRecordSet2 ConvertToRecordset(IFeatureClass fc) { IRecordSet recSet = new RecordSetClass(); IRecordSetInit recSetInit = recSet as IRecordSetInit; recSetInit.SetSourceTable(fc as ITable, null); return (IRecordSet2)recSetInit; }
//����һ��FeatureClassΪ�ļ� by gisoracle //public void saveFeatureClass(IFeatureClass pFeatureClass, string fileName) //{ // try // { // string sFileName = System.IO.Path.GetFileName(fileName); // string sFilePath = System.IO.Path.GetDirectoryName(fileName); // IDataset pDataset = pFeatureClass as IDataset; // IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); // IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0) as IFeatureWorkspace; // IWorkspace pWorkspace = pFeatureWorkspace as IWorkspace; // if (pWorkspace.Exists() == true) // { // //DelFeatureFile(sFilePath, sFileName); // } // //pDataset.Copy(sFileName, pFeatureWorkspace as IWorkspace); // } // catch { MessageBox.Show("����"); } //} //by gisoracle public static void DelFeatureFile(IFeatureClass pFeatureClass, string sName) { if (pFeatureClass!= null) { IDataset dataset = pFeatureClass as IDataset; dataset.Delete(); } }
public OperateForm(IFeatureClass FeatureClass, IFeature Feature) { this.FeatureClass = FeatureClass; this.Feature = Feature; this.FieldIndexDict = GISHelper.GetFieldIndexDict(FeatureClass); Init(); InitializeComponent(); }
public OperateForm(IFeatureClass FeatureClass, IGeometry geometry) { this.FeatureClass = FeatureClass; this.FieldIndexDict = GISHelper.GetFieldIndexDict(FeatureClass); this.geometry = geometry; Init(); InitializeComponent(); }
void IAppend.Append(IFeatureClass fcSource, IFeatureClass fcTarget) { Geoprocessor gp = new Geoprocessor(); ESRI.ArcGIS.DataManagementTools.Append pAppend = new ESRI.ArcGIS.DataManagementTools.Append(fcSource, fcTarget); gp.SetEnvironmentValue("workspace",this._environment); pAppend.schema_type = "NO_TEST"; runTool(gp, pAppend, null); }
public dataPrepAdjustAccuracyAssessment(IFeatureClass ProjectArea, IRaster Map, string originalAccuracyAssessmentModel, string adjustedAccuracyAssessmentModel) { projectArea = ProjectArea; rstMap = Map; oModel = originalAccuracyAssessmentModel; aModel = adjustedAccuracyAssessmentModel; rsUtil = new rasterUtil(); }
public PolygonsPartitionAggregation(IFeatureClass feacls,string resultPath,string gradeField) { m_GP = new Geoprocessor(); m_FeaCls = feacls; m_PartitionField = gradeField; m_WorkingPath = resultPath; }
public AttributeForm(IFeature feature, IFeatureClass featureClass, IFeatureClass historyFC, IFeatureClass crossFC, string LayerName) { InitializeComponent(); this.Feature = feature; this.FeatureClass = featureClass; this.LayerName = LayerName; this.HistoryFC = historyFC; this.CrossFC = crossFC; }
public static List<Dictionary<int, List<IPoint>>> QueryIntersectPoints(List<IPolyline> lines, IFeatureClass roadFC) { var list = new List<Dictionary<int, List<IPoint>>>(); foreach(var line in lines) { list.Add(QueryIntersectPoints(line, roadFC)); } return list; }
public SelectedObjects(IFeatureClass pFC) { IDataset pDS; pDS = (IDataset)pFC; iClassID = pFC.FeatureClassID; sClassName = pDS.Name; pSelSet = pFC.Select(null, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionEmpty, pDS.Workspace); }
public GHYT(IFeatureClass pFeatureClass, IFeature pFeatrue) { this.BSM = pFeatrue.get_Value(pFeatureClass.Fields.FindField(this.BSM)).ToString(); this.YSDM = pFeatrue.get_Value(pFeatureClass.Fields.FindField(this.YSDM)).ToString(); this.XZQHDM = pFeatrue.get_Value(pFeatureClass.Fields.FindField(this.XZQHDM)).ToString(); this.GNFQLXDM = pFeatrue.get_Value(pFeatureClass.Fields.FindField(this.GNFQLXDM)).ToString(); this.TDLYGNFQBH = pFeatrue.get_Value(pFeatureClass.Fields.FindField(this.TDLYGNFQBH)).ToString(); this.GNFQMJ = pFeatrue.get_Value(pFeatureClass.Fields.FindField(this.GNFQMJ)).ToString(); }
public HistoryForm(int fid, IFeatureClass roadFC, IFeatureClass roadHistoryFC, IFeatureClass roadNodeFC, MainForm parent) { InitializeComponent(); m_fid = fid; m_RoadFC = roadFC; m_RoadHistoryFC = roadHistoryFC; m_RoadNodeFC = roadNodeFC; m_Parent = parent; }
public FormAttributeTable(AxMapControl pMapControl, IMapControl3 pMapCtrl) { InitializeComponent(); _MapControl = pMapControl; m_mapControl = pMapCtrl; ILayer pLayer = (ILayer)m_mapControl.CustomProperty; pFLayer = pLayer as IFeatureLayer; pFClass = pFLayer.FeatureClass; }
public BusResultForm(IFeatureClass FeatureClass,IFeatureClass BusStopFeatureClass,string WhereClause) { InitializeComponent(); this.FeatureClass = FeatureClass; this.WhereClause = WhereClause; this.BusStopFeatureClass=BusStopFeatureClass; this.IndexDirect = FeatureClass.Fields.FindField("lineDirect"); this.IndexNameShort = FeatureClass.Fields.FindField("nameshort"); }
/// <summary> /// ��������ͼ�������ڵ�Ҫ�� /// </summary> /// <param name="fc"></param> /// <param name="geo"></param> /// <returns></returns> public static IFeatureCursor SearchContainFeat(IFeatureClass fc, IGeometry geo) { ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = geo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; IFeatureCursor pfeatCursor = fc.Search(pSpatialFilter, false); return pfeatCursor; }
/// <summary> /// ����Ҫ�ؼ����������ͼ���ཻ��Ҫ�أ��������α� /// </summary> /// <param name="LineFeatClass"></param> /// <param name="geo"></param> /// <returns></returns> public static IFeatureCursor SearchIntersectLineFeat(IFeatureClass LineFeatClass, IGeometry geo) { ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = geo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; IFeatureCursor pfeatCursor = LineFeatClass.Search(pSpatialFilter, false); return pfeatCursor; }
public ImportRoadForm(List<IPolyline> newRoads, IFeatureClass fc, IFeatureClass historyFC, IFeatureClass crossFC, IList<RoadCrossInfo> infos) { InitializeComponent(); m_RoadFeatureClass = fc; m_RoadHistoryFC = historyFC; m_RoadCrossFC = crossFC; m_Polylines = newRoads; m_Crossroads.Clear(); m_Crossroads.AddRange(infos); }
public void AddField(IFeatureClass pFeatureClass,string fieldName,esriFieldType fieldType) { //如果存在不必添加字段,直接返回 if (pFeatureClass.FieldExistCheck(fieldName)) return; var pField = new FieldClass(); var pFieldEdit = (IFieldEdit)pField; pFieldEdit.Name_2 = fieldName; pFieldEdit.Type_2 = fieldType; pFeatureClass.AddField(pFieldEdit); }
private IRepresentationWorkspaceExtension GetRepWSExtFromFeatureClass(IFeatureClass theFeatureClass) { IDataset theDS = theFeatureClass as IDataset; IWorkspace theWorkspace = theDS.Workspace; IWorkspaceExtensionManager theExtManager = theWorkspace as IWorkspaceExtensionManager; UID theUID = new UIDClass(); theUID.Value = "{FD05270A-8E0B-4823-9DEE-F149347C32B6}"; return theExtManager.FindExtension(theUID) as IRepresentationWorkspaceExtension; }
async public Task <bool> Insert(IFeatureClass fClass, List <IFeature> features) { try { var featureCollection = await GetFeatureCollection(fClass); if (featureCollection == null) { throw new Exception("No feature collection. Open database before running CreateFeatureClass method"); } var spatialCollectionItem = await(await _spatialCollectionRef.FindAsync(s => s.Name == fClass.Name)).FirstOrDefaultAsync(); if (spatialCollectionItem == null) { throw new Exception("Feature class not exists"); } IEnvelope bounds = spatialCollectionItem.FeatureBounds?.ToEnvelope(); int fieldCount = fClass.Fields.Count; int degreeOfParallelism = 1; var containers = new List <Json.GeometryDocument> [degreeOfParallelism]; for (int i = 0; i < degreeOfParallelism; i++) { containers[i] = new List <Json.GeometryDocument>(); } var generalizationLevel = fClass is MongoDbFeatureClass ? ((MongoDbFeatureClass)fClass).GeneralizationLevel : -1; int counter = 0; foreach (var feature in features) { var document = new Json.GeometryDocument(); var documentProperties = new Dictionary <string, object>(); if (feature.Shape != null) { document.Shape = feature.Shape.ToGeoJsonGeometry <GeoJson2DGeographicCoordinates>(); if (bounds == null) { bounds = new Envelope(feature.Shape.Envelope); } else { bounds.Union(feature.Shape.Envelope); } if (fClass.GeometryType != geometryType.Point) { document.Bounds = feature.Shape.Envelope.ToPolygon(0).ToGeoJsonGeometry <GeoJson2DGeographicCoordinates>(); document.AppendGeneralizedShapes(feature.Shape, fClass.SpatialReference, generalizationLevel); } #region Generalize // dpm = 96/0.0254 // tol = pix * s / dpm // // pix = dpm/s (tol=1) -> 1 Pixel sind beim 1:s pix[m] #endregion } for (int f = 0; f < fieldCount; f++) { var field = fClass.Fields[f]; if (field.type == FieldType.ID || field.type == FieldType.Shape) { continue; } var fieldValue = feature.FindField(field.name); if (fieldValue != null) { if (fieldValue.Value == DBNull.Value) { fieldValue.Value = null; } documentProperties.Add(fieldValue.Name, fieldValue.Value); } } document.Properties = documentProperties; containers[counter % degreeOfParallelism].Add(document); counter++; } //Task[] tasks = new Task[degreeOfParallelism]; //for (int i = 0; i < degreeOfParallelism; i++) //{ // tasks[i] = Task.Factory.StartNew(async (object index) => // { // await featureCollection.InsertManyAsync(containers[(int)index]); // }, (object)i); //} //await Task.WhenAll(tasks); await featureCollection.InsertManyAsync(containers[0]); var updateResult = await _spatialCollectionRef.UpdateOneAsync <Json.SpatialCollectionItem>( c => c.Id == spatialCollectionItem.Id, Builders <Json.SpatialCollectionItem> .Update.Set(i => i.FeatureBounds, new Json.SpatialCollectionItem.Bounds(bounds))); return(true); } catch (Exception ex) { lastException = ex; LastErrorMessage = ex.Message; return(false); } }
/* * A function to populate a referenced FeatureClass (fc) with the contents of a Google Maps Engine map */ public void populateFCWithGoogleMapsEngineMap(ref IFeatureClass fc, ref MapsEngine.DataModel.gme.Map map) { // create a feature object log.Debug("Creating a new Feature object to be used later in populating the FC."); IFeature feature = fc.CreateFeature(); log.Debug("Creating feature for map " + map.id); // create a projectId value from the MapId String projectId = map.id.Split("-".ToCharArray())[0]; // Update the values for this feature feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_CustomerId_Name), projectId); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_CustomerId_Name + ": " + projectId); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetId_Name), map.id); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetId_Name + ": " + map.id); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_Name), map.id); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_Name + ": " + map.id); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name), "map"); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name + ": " + "map"); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetName_Name), map.name); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetName_Name + ": " + map.name); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_Name), projectId); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_Name + ": " + projectId); // attempt to set the description try { // attempt to set the feature description (truncating if necessary) feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_Name) , map.description.Length > 256 ? map.description.Substring(0, 252) + "..." : map.description); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_Name + ": " + map.description); } catch (System.Exception ex) { // warn log.Warn(ex); } // check to see if the bbox object is not null log.Debug("Adding spatial representation if available."); if (map.bbox != null && map.bbox.Count() == 4) { // deterine the maximum and minimum bounds of all layers within this map // 0=West, 1=South, 2=East, 3=North double XMAX = map.bbox[2]; log.Debug("XMAX: " + XMAX); double YMAX = map.bbox[3]; log.Debug("YMAX: " + YMAX); double XMIN = map.bbox[0]; log.Debug("XMIN: " + XMIN); double YMIN = map.bbox[1]; log.Debug("YMIN: " + YMIN); // determine the map extent based on the layers maximum extent IPoint pExtentNE = new Point(); pExtentNE.X = XMAX; pExtentNE.Y = YMAX; IPoint pExtentSW = new Point(); pExtentSW.X = XMIN; pExtentSW.Y = YMIN; IPoint pExtentNW = new Point(); pExtentNW.X = XMIN; pExtentNW.Y = YMAX; IPoint pExtentSE = new Point(); pExtentSE.X = XMAX; pExtentSE.Y = YMIN; // define the polygon bounding box (NE/SW) as a point collection log.Debug("Building polygon object."); IPointCollection pExtentPointCol = new Polygon(); pExtentPointCol.AddPoint(pExtentNE, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentSE, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentSW, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentNW, Type.Missing, Type.Missing); // create a polygon, p, from the point collection, then close the polygon IPolygon pExtent = (IPolygon)pExtentPointCol; pExtent.Close(); // add the polygon, p, as the new feature's geometry if (pExtent != null) { log.Debug("Setting feature's geometry."); feature.Shape = pExtent; } else { log.Warn("Polygon is not valid, setting feature geometry to default worldwide."); feature.Shape = worldPolygon; } } else { // no spatial information contained, use world log.Warn("No spatial representation, setting feature geometry to default worldwide."); //feature.Shape = worldPolygon; } // Commit the new feature to fc log.Debug("Storing feature."); feature.Store(); // add all child layers within this map log.Debug("Verifying the map has layers."); if (map.layers != null) { // go through each layer in the map log.Debug("Going through each layer in the map."); foreach (MapsEngine.DataModel.gme.MapLayer layer in map.layers) { // populate the features in the layer log.Debug("Processing layer " + layer.id); populateFCWithGoogleMapsEngineLayer(ref fc, map.id, map.id, layer); } } // Verifying the map has a folders object log.Debug("Verifying the map has a folders object."); if (map.folders != null && map.folders.Count() > 0) { // populate the features in the folder log.Debug("Processing folders"); populateFCWithGoogleMapsEngineFolders(ref fc, map.id, map.id, map.folders); } }
private void buttonGetValue_Click(object sender, EventArgs e) { if (listBoxFields.Text == "") { MessageBox.Show("请选择一个属性字段!"); return; } string strSelectedFieldName = listBoxFields.Text;//这个名字是选中的属性字段的名称 listBoxValues.Items.Clear(); valueCounts.Text = ""; if (strSelectedFieldName == null) { return; } IFeatureClass pFeatureClass = (GetLayerByName(comboBoxLayers.Text) as IFeatureLayer).FeatureClass; if (pFeatureClass == null) { return; } int fieldIdx = pFeatureClass.Fields.FindField(strSelectedFieldName); IField field = pFeatureClass.Fields.get_Field(fieldIdx); try { System.Collections.IEnumerator uniqueValues = GetUniqueValues(pFeatureClass, strSelectedFieldName); if (uniqueValues == null) { return; } if ((field.Type == esriFieldType.esriFieldTypeDouble) || (field.Type == esriFieldType.esriFieldTypeInteger) || (field.Type == esriFieldType.esriFieldTypeSingle) || (field.Type == esriFieldType.esriFieldTypeSmallInteger)) { System.Collections.Generic.List <double> valuesList = new System.Collections.Generic.List <double>(); while (uniqueValues.MoveNext()) { valuesList.Add(double.Parse(uniqueValues.Current.ToString())); } valuesList.Sort(); foreach (object uniqueValue in valuesList) { listBoxValues.Items.Add(uniqueValue.ToString()); } } else { System.Collections.Generic.List <object> valuesList = new System.Collections.Generic.List <object>(); while (uniqueValues.MoveNext()) { valuesList.Add(uniqueValues.Current); } valuesList.Sort(); foreach (object uniqueValue in valuesList) { listBoxValues.Items.Add(uniqueValue.ToString()); } } valueCounts.Text = GetUniqueValuesCount(pFeatureClass, strSelectedFieldName).ToString() + "个值"; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static ClsMapLayer QueryByAttribute(bool blnSelect, string whereClause, esriSelectionResultEnum pOperator, IFeatureClass pFeatCls, IFeatureLayer pFeatlayer) { ClsMapLayer pQueryByAttribute = new ClsMapLayer(); //IActiveView pActiveView; IQueryFilter pFilter = new QueryFilterClass(); pFilter.SubFields = "*"; pFilter.WhereClause = whereClause; pQueryByAttribute.FeatCls = pFeatCls; IDataset pDataset; pDataset = (IDataset)pFeatCls; IFeatureSelection pFeatSelection; ICursor pCursor; if (blnSelect == true) { pQueryByAttribute.FeatLayer = pFeatlayer; pFeatSelection = (IFeatureSelection)pFeatlayer; pFeatSelection.SelectFeatures(pFilter, pOperator, false); pQueryByAttribute.FeatSelectionSet = pFeatSelection.SelectionSet as ISelectionSet2; pQueryByAttribute.FeatSelectionSet.Search(null, false, out pCursor); if (pCursor is IFeatureCursor) { pQueryByAttribute.FeatCur = (IFeatureCursor)pCursor; } return(pQueryByAttribute); //pActiveView = ClsDeclare.g_pMap as IActiveView; //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } else { pQueryByAttribute.FeatLayer = pFeatlayer; //esriSelectionOption pSelectionOption=new esriSelectionOption(); pQueryByAttribute.FeatSelectionSet = pQueryByAttribute.FeatCls.Select(pFilter, esriSelectionType.esriSelectionTypeHybrid, (esriSelectionOption)(int)pOperator, pDataset.Workspace) as ISelectionSet2; pQueryByAttribute.FeatSelectionSet.Search(null, false, out pCursor); if (pCursor is IFeatureCursor) { pQueryByAttribute.FeatCur = (IFeatureCursor)pCursor; } return(pQueryByAttribute); } }
async public Task <IFeatureCursor> Query(IFeatureClass fc, IQueryFilter filter) { return(new MongoDbFeatureCursor((MongoDbFeatureClass)fc, filter)); }
public void OnMouseUp(int button, int shift, int x, int y) { if (shift == 0) { //清除所有选择的内容 m_Map.ClearSelection(); m_activeView.Refresh(); } if (button != 1) { return; } try { if (m_EngineEditor == null) { return; } if (m_EngineEditor.EditState != esriEngineEditState.esriEngineStateEditing) { return; } if (m_EngineEditLayers == null) { return; } //获取目标图层 IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; IFeatureClass pFeatCls = pFeatLyr.FeatureClass; //MapControl axMapControl1 = Control.FromHandle(new IntPtr(this.m_hookHelper.ActiveView.ScreenDisplay.hWnd)) as MapControl; IMapControl4 axMapControl1 = GlobalVars.instance.MapControl; IEnvelope pEnvelope = axMapControl1.TrackRectangle(); IGeometry pGeometry = null; //当点选的情况时,Envelope为空,此时建立缓冲区 if (pEnvelope.IsEmpty == true) { IPoint point = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); //定义缓冲区 double db = MapManager.ConvertPixelsToMapUnits(m_activeView, 4); ITopologicalOperator pTop; pTop = point as ITopologicalOperator; pGeometry = pTop.Buffer(db); } else { pGeometry = pEnvelope as IGeometry; } //设置选择过滤条件 ISpatialFilter pSpatialFilter = new SpatialFilterClass(); //不同的图层类型设置不同的过滤条件 switch (pFeatCls.ShapeType) { case esriGeometryType.esriGeometryPoint: //将像素距离转换为地图单位距离 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolygon: pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeometryPolyline: pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; } pSpatialFilter.Geometry = pGeometry; pSpatialFilter.GeometryField = pFeatCls.ShapeFieldName; IQueryFilter pQueryFilter = pSpatialFilter as IQueryFilter; //根据过滤条件进行查询 IFeatureCursor pFeatCursor = pFeatCls.Search(pQueryFilter, false); IFeature pFeature = pFeatCursor.NextFeature(); IFeatureSelection pFeatureSelection; pFeatureSelection = pFeatLyr as IFeatureSelection; IEnumFeature pEnumFeature2 = m_Map.FeatureSelection as IEnumFeature;//已经选择的选择集 int a = pFeatureSelection.SelectionSet.Count; pEnumFeature2.Reset(); IFeature pFeature2 = pEnumFeature2.Next(); //遍历整个要素类中符合条件的要素 while (pFeature != null) { if (pFeature2 == null) { pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, false); break; } //遍历当前选择的要素 while (pFeature2 != null) { IRelationalOperator re = (IRelationalOperator)pFeature.Shape; if (re.Equals(pFeature2.Shape)) { pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultSubtract, false); break; } else { m_Map.SelectFeature(pFeatLyr as ILayer, pFeature); } pFeature2 = pEnumFeature2.Next(); } pFeature = pFeatCursor.NextFeature(); } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatCursor); } catch (Exception ex) { //SysLogHelper.WriteOperationLog("选择要素错误", ex.Source, "数据编辑"); } }
public void CopyAnnotationFeatures1() { try { IMxDocument pMxDoc = (IMxDocument)ArcMap.Application.Document; IMap pMap = pMxDoc.FocusMap; ILayer FromLayer = pMap.Layer[0]; ILayer ToLayer = pMap.Layer[1]; IFeatureLayer FromLayerFeature = (IFeatureLayer)FromLayer; IFeatureLayer ToLayerFeature = (IFeatureLayer)ToLayer; IFeatureClass FromFeatureClass = FromLayerFeature.FeatureClass; IFeatureClass ToFeatureClass = ToLayerFeature.FeatureClass; IFeatureBuffer featureBuffer = ToFeatureClass.CreateFeatureBuffer(); IFeatureCursor insertCursor = ToFeatureClass.Insert(true); int iFeatureID = ToFeatureClass.FindField("FeatureID"); int iZOrder = ToFeatureClass.FindField("ZOrder"); int iAnnotationClassid = ToFeatureClass.FindField("AnnotationClassID"); int iSymbolId = ToFeatureClass.FindField("SymbolID"); int iStatus = ToFeatureClass.FindField("Status"); int iTextString = ToFeatureClass.FindField("TextString"); int iFontName = ToFeatureClass.FindField("FontName"); int iFontSize = ToFeatureClass.FindField("FontSize"); int iBold = ToFeatureClass.FindField("Bold"); int iItalic = ToFeatureClass.FindField("Italic"); int iUnderline = ToFeatureClass.FindField("Underline"); int iVerticalAlignment = ToFeatureClass.FindField("VerticalAlignment"); int iHorizontalAlignment = ToFeatureClass.FindField("HorizontalAlignment"); int iXoffset = ToFeatureClass.FindField("XOffset"); int iYoffset = ToFeatureClass.FindField("YOffset"); int iAngle = ToFeatureClass.FindField("FontLeading"); int iWordspacing = ToFeatureClass.FindField("WordSpacing"); int iCharacterWidth = ToFeatureClass.FindField("CharacterWidth"); int iCharacterSpacing = ToFeatureClass.FindField("CharacterSpacing"); int iFlipAngle = ToFeatureClass.FindField("FlipAngle"); int iOverride = ToFeatureClass.FindField("Override"); IFeatureCursor searchCursor = FromFeatureClass.Search(null, true); int sFeatureID = FromFeatureClass.FindField("FeatureID"); int sZOrder = FromFeatureClass.FindField("ZOrder"); int sAnnotationClassid = FromFeatureClass.FindField("AnnotationClassID"); int sSymbolId = FromFeatureClass.FindField("SymbolID"); int sStatus = FromFeatureClass.FindField("Status"); int sTextString = FromFeatureClass.FindField("TextString"); int sFontName = FromFeatureClass.FindField("FontName"); int sFontSize = FromFeatureClass.FindField("FontSize"); int sBold = FromFeatureClass.FindField("Bold"); int sItalic = FromFeatureClass.FindField("Italic"); int sUnderline = FromFeatureClass.FindField("Underline"); int sVerticalAlignment = FromFeatureClass.FindField("VerticalAlignment"); int sHorizontalAlignment = FromFeatureClass.FindField("HorizontalAlignment"); int sXoffset = FromFeatureClass.FindField("XOffset"); int sYoffset = FromFeatureClass.FindField("YOffset"); int sAngle = FromFeatureClass.FindField("FontLeading"); int sWordspacing = FromFeatureClass.FindField("WordSpacing"); int sCharacterWidth = FromFeatureClass.FindField("CharacterWidth"); int sCharacterSpacing = FromFeatureClass.FindField("CharacterSpacing"); int sFlipAngle = FromFeatureClass.FindField("FlipAngle"); int sOverride = FromFeatureClass.FindField("Override"); IFeature feature; while ((feature = searchCursor.NextFeature()) != null) { featureBuffer.Shape = feature.Shape; featureBuffer.Value[iFeatureID] = feature.Value[sFeatureID]; featureBuffer.Value[iZOrder] = feature.Value[sZOrder]; featureBuffer.Value[iAnnotationClassid] = feature.Value[sAnnotationClassid]; featureBuffer.Value[iSymbolId] = feature.Value[sSymbolId]; featureBuffer.Value[iStatus] = feature.Value[sStatus]; featureBuffer.Value[iTextString] = feature.Value[sTextString]; featureBuffer.Value[iFontName] = feature.Value[sFontName]; featureBuffer.Value[iFontSize] = feature.Value[sFontSize]; featureBuffer.Value[iBold] = feature.Value[sBold]; featureBuffer.Value[iItalic] = feature.Value[sItalic]; featureBuffer.Value[iUnderline] = feature.Value[sUnderline]; featureBuffer.Value[iVerticalAlignment] = feature.Value[sVerticalAlignment]; featureBuffer.Value[iHorizontalAlignment] = feature.Value[sHorizontalAlignment]; featureBuffer.Value[iXoffset] = feature.Value[sXoffset]; featureBuffer.Value[iYoffset] = feature.Value[sYoffset]; featureBuffer.Value[iAngle] = feature.Value[sAngle]; featureBuffer.Value[iWordspacing] = feature.Value[sWordspacing]; featureBuffer.Value[iCharacterWidth] = feature.Value[sCharacterWidth]; featureBuffer.Value[iCharacterSpacing] = feature.Value[sCharacterSpacing]; featureBuffer.Value[iFlipAngle] = feature.Value[sFlipAngle]; insertCursor.InsertFeature(featureBuffer); insertCursor.Flush(); } System.Runtime.InteropServices.Marshal.FinalReleaseComObject(searchCursor); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(insertCursor); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public FcListViewItem(IFeatureClass fc) { _fc = fc; base.Text = _fc.Name; }
private void CreateLines() { //创建要素类 #region 创建新的内存工作空间 IWorkspaceFactory pWSF = new InMemoryWorkspaceFactoryClass(); IWorkspaceName pWSName = pWSF.Create("", "Temp", null, 0); IName pName = (IName)pWSName; IWorkspace pMemoryWS = (IWorkspace)pName.Open(); #endregion IField oField = new FieldClass(); IFields oFields = new FieldsClass(); IFieldsEdit oFieldsEdit = null; IFieldEdit oFieldEdit = null; IFeatureClass oFeatureClass = null; IFeatureLayer oFeatureLayer = null; oFieldsEdit = oFields as IFieldsEdit; oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "OBJECTID"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; oFieldEdit.IsNullable_2 = false; oFieldEdit.Required_2 = false; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; IGeometryDef pGeoDef = new GeometryDefClass(); IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef; pGeoDefEdit.AvgNumPoints_2 = 5; pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; pGeoDefEdit.GridCount_2 = 1; pGeoDefEdit.HasM_2 = false; pGeoDefEdit.HasZ_2 = false; pGeoDefEdit.SpatialReference_2 = axMapControl.SpatialReference; oFieldEdit.Name_2 = "SHAPE"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; oFieldEdit.GeometryDef_2 = pGeoDef; oFieldEdit.IsNullable_2 = true; oFieldEdit.Required_2 = true; oFieldsEdit.AddField(oField); oField = new FieldClass(); oFieldEdit = oField as IFieldEdit; oFieldEdit.Name_2 = "Code"; oFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger; //oFieldEdit.Length = 10; oFieldEdit.IsNullable_2 = true; oFieldsEdit.AddField(oField); //创建要素类 oFeatureClass = (pMemoryWS as IFeatureWorkspace).CreateFeatureClass("Temp", oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); oFeatureLayer = new FeatureLayerClass(); oFeatureLayer.Name = "PointLayer"; oFeatureLayer.FeatureClass = oFeatureClass; //创建唯一值符号化对象 IUniqueValueRenderer pURender = new UniqueValueRendererClass(); pURender.FieldCount = 1; pURender.set_Field(0, "Code"); pURender.UseDefaultSymbol = false; //创建SimpleMarkerSymbolClass对象 ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); //创建RgbColorClass对象为pSimpleMarkerSymbol设置颜色 IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pSimpleMarkerSymbol.Color = pRgbColor as IColor; //设置pSimpleMarkerSymbol对象的符号类型,选择钻石 pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond; //设置pSimpleMarkerSymbol对象大小,设置为5 pSimpleMarkerSymbol.Size = 5; //显示外框线 pSimpleMarkerSymbol.Outline = true; //为外框线设置颜色 IRgbColor pLineRgbColor = new RgbColorClass(); pLineRgbColor.Green = 255; pSimpleMarkerSymbol.OutlineColor = pLineRgbColor as IColor; //设置外框线的宽度 pSimpleMarkerSymbol.OutlineSize = 1; //半透明颜色 pURender.AddValue("Marker01", "", pSimpleMarkerSymbol as ISymbol); //唯一值符号化内存图层 (oFeatureLayer as IGeoFeatureLayer).Renderer = pURender as IFeatureRenderer; ILayerEffects pLyrEffect = oFeatureLayer as ILayerEffects; //透明度 pLyrEffect.Transparency = 0; oFeatureLayer.Visible = true; this.axMapControl.AddLayer(oFeatureLayer, axMapControl.LayerCount); //AddPointByBuffer(0); //insertpoint = true; }
private void btnCreate_Click(object sender, EventArgs e) { try { frmProgress pfrmProgress = new frmProgress(); pfrmProgress.bgWorker.ReportProgress(0); pfrmProgress.lblStatus.Text = "Create Flow Lines"; pfrmProgress.Show(); string strOutput = txtOutput.Text; string strOutputPath = System.IO.Path.GetDirectoryName(strOutput); string strOutputName = System.IO.Path.GetFileName(strOutput); ISpatialReference pSpatialRef = null; if (cboSpatialInfo.Text == "From ShapeFile") { IGeoDataset geoDataset = m_pFClass as IGeoDataset; pSpatialRef = geoDataset.SpatialReference; } //Create New FeatureClass IFeatureClass pFCOutput = CreateShapeFile(strOutputPath, strOutputName, pSpatialRef, esriGeometryType.esriGeometryPolyline); //Add Fld Ids to added in new FC int[] intAddFldIdsInTable = null; int intCheckedFldCnt = clistFields.CheckedItems.Count; if (intCheckedFldCnt > 0) { intAddFldIdsInTable = new int[intCheckedFldCnt]; for (int i = 0; i < intCheckedFldCnt; i++) { intAddFldIdsInTable[i] = m_tblFlow.FindField((string)clistFields.CheckedItems[i]); } } AddFldsFromTable(pFCOutput, m_tblFlow, intAddFldIdsInTable); //Get Ids from FeatureClass int[] intAddFldIdsInFC = null; if (intCheckedFldCnt > 0) { intAddFldIdsInFC = new int[intCheckedFldCnt]; for (int i = 0; i < intCheckedFldCnt; i++) { intAddFldIdsInFC[i] = pFCOutput.FindField((string)clistFields.CheckedItems[i]); } } var watch = Stopwatch.StartNew(); if (cboSpatialInfo.Text == "From Table") { //First Method, it takes some times, require better algorithm. 0714 HK string strFromXFld = cbo1.Text; string strFromYFld = cbo2.Text; string strToXFld = cbo3.Text; string strToYFld = cbo4.Text; int intFromXIdx = m_tblFlow.FindField(strFromXFld); int intFromYIdx = m_tblFlow.FindField(strFromYFld); int intToXIdx = m_tblFlow.FindField(strToXFld); int intToYIdx = m_tblFlow.FindField(strToYFld); int intTotalFlowCnt = m_tblFlow.RowCount(null); ICursor pCursor = m_tblFlow.Search(null, false); IRow pRow = pCursor.NextRow(); //IPoint pFromPt = new ESRI.ArcGIS.Geometry.Point(); //IPoint pToPts = new ESRI.ArcGIS.Geometry.Point(); IPoint pFromPt = null; IPoint pToPt = null; double dblFromX = 0, dblFromY = 0, dblToX = 0, dblToY = 0; IPolyline pPolyline = new PolylineClass(); int cnt = 0; if (intCheckedFldCnt > 0) { while (pRow != null) { int intProgress = cnt * 100 / intTotalFlowCnt; pfrmProgress.bgWorker.ReportProgress(intProgress); dblFromX = Convert.ToDouble(pRow.get_Value(intFromXIdx)); dblFromY = Convert.ToDouble(pRow.get_Value(intFromYIdx)); dblToX = Convert.ToDouble(pRow.get_Value(intToXIdx)); dblToY = Convert.ToDouble(pRow.get_Value(intToYIdx)); pFromPt = new PointClass(); pToPt = new PointClass(); pFromPt.PutCoords(dblFromX, dblFromY); pToPt.PutCoords(dblToX, dblToY); pPolyline = new PolylineClass(); pPolyline.FromPoint = pFromPt; pPolyline.ToPoint = pToPt; IFeature pFeature = pFCOutput.CreateFeature(); pFeature.Shape = pPolyline; for (int i = 0; i < intCheckedFldCnt; i++) { pFeature.set_Value(intAddFldIdsInFC[i], pRow.get_Value(intAddFldIdsInTable[i])); } pFeature.Store(); pRow = pCursor.NextRow(); cnt++; } } else { int intProgress = cnt * 100 / intTotalFlowCnt; pfrmProgress.bgWorker.ReportProgress(intProgress); dblFromX = Convert.ToDouble(pRow.get_Value(intFromXIdx)); dblFromY = Convert.ToDouble(pRow.get_Value(intFromYIdx)); dblToX = Convert.ToDouble(pRow.get_Value(intToXIdx)); dblToY = Convert.ToDouble(pRow.get_Value(intToYIdx)); pFromPt = new PointClass(); pToPt = new PointClass(); pFromPt.PutCoords(dblFromX, dblFromY); pToPt.PutCoords(dblToX, dblToY); pPolyline = new PolylineClass(); pPolyline.FromPoint = pFromPt; pPolyline.ToPoint = pToPt; IFeature pFeature = pFCOutput.CreateFeature(); pFeature.Shape = pPolyline; pFeature.Store(); pRow = pCursor.NextRow(); cnt++; } #region deprecated 101917 HK // //Second Method, it takes similar calculation time. 0714 HK // string strFromXFld = cbo1.Text; // string strFromYFld = cbo2.Text; // string strToXFld = cbo3.Text; // string strToYFld = cbo4.Text; // int intFromXIdx = m_tblFlow.FindField(strFromXFld); // int intFromYIdx = m_tblFlow.FindField(strFromYFld); // int intToXIdx = m_tblFlow.FindField(strToXFld); // int intToYIdx = m_tblFlow.FindField(strToYFld); // int intTotalFlowCnt = m_tblFlow.RowCount(null); // ICursor pCursor = m_tblFlow.Search(null, false); // IRow pRow = pCursor.NextRow(); // //IPoint pFromPt = new ESRI.ArcGIS.Geometry.Point(); // //IPoint pToPts = new ESRI.ArcGIS.Geometry.Point(); // IPoint pFromPt = null; // IPoint pToPt = null; // IPolyline pPolyline = new PolylineClass(); // double[][] dblValues = new double[intTotalFlowCnt][]; // int cnt = 0; // while (pRow != null) // { // pfrmProgress.lblStatus.Text = "Collect data"; // int intProgress = cnt * 100 / intTotalFlowCnt; // pfrmProgress.bgWorker.ReportProgress(intProgress); // dblValues[cnt] = new double[4 + intCheckedFldCnt]; // dblValues[cnt][0] = Convert.ToDouble(pRow.get_Value(intFromXIdx)); // dblValues[cnt][1] = Convert.ToDouble(pRow.get_Value(intFromYIdx)); // dblValues[cnt][2] = Convert.ToDouble(pRow.get_Value(intToXIdx)); // dblValues[cnt][3] = Convert.ToDouble(pRow.get_Value(intToYIdx)); // if (intCheckedFldCnt > 0) // for (int i = 0; i < intCheckedFldCnt; i++) // dblValues[cnt][3+i] = Convert.ToDouble(pRow.get_Value(intAddFldIdsInTable[i])); // pRow = pCursor.NextRow(); // cnt++; // } // for(int j = 0; j<intTotalFlowCnt; j++) // { // pfrmProgress.lblStatus.Text = "Create Line"; // int intProgress = j * 100 / intTotalFlowCnt; // pfrmProgress.bgWorker.ReportProgress(intProgress); // pFromPt = new PointClass(); // pToPt = new PointClass(); // pFromPt.PutCoords(dblValues[j][0], dblValues[j][1]); // pToPt.PutCoords(dblValues[j][2], dblValues[j][3]); // pPolyline = new PolylineClass(); // pPolyline.FromPoint = pFromPt; // pPolyline.ToPoint = pToPt; // IFeature pFeature = pFCOutput.CreateFeature(); // pFeature.Shape = pPolyline; // if (intCheckedFldCnt > 0) // for (int i = 0; i < intCheckedFldCnt; i++) // pFeature.set_Value(intAddFldIdsInFC[i], dblValues[j][3+i]); // pFeature.Store(); // } #endregion } else if (cboSpatialInfo.Text == "From ShapeFile") { string strRefSHPName = cbo1.Text; string strJoinFldName = cbo2.Text; string strOIDFldName = cbo3.Text; string strDIDFldName = cbo4.Text; int intJoinFldIdx = m_pFClass.FindField(strJoinFldName); int intOIDIdx = m_tblFlow.FindField(strOIDFldName); int intDIDIdx = m_tblFlow.FindField(strDIDFldName); int intFeatureCount = m_pFClass.FeatureCount(null); IFeatureCursor pFCursor = m_pFClass.Search(null, true); IFeature pFeature = pFCursor.NextFeature(); List <RefSpatialInfo> lstRefInfo = new List <RefSpatialInfo>(); IArea pArea; IPoint pPoint; int cnt = 0; while (pFeature != null) { pfrmProgress.lblStatus.Text = "Getting Spatial Information from Shape file"; int intProgress = cnt * 100 / intFeatureCount; pfrmProgress.bgWorker.ReportProgress(intProgress); RefSpatialInfo RefInfo = new RefSpatialInfo(); RefInfo.JoinID = pFeature.get_Value(intJoinFldIdx).ToString(); if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon) { pArea = (IArea)pFeature.Shape; RefInfo.XCoor = pArea.Centroid.X; RefInfo.YCoor = pArea.Centroid.Y; } else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { pPoint = (IPoint)pFeature.Shape; RefInfo.XCoor = pPoint.X; RefInfo.YCoor = pPoint.Y; } lstRefInfo.Add(RefInfo); cnt++; pFeature = pFCursor.NextFeature(); } pFCursor.Flush(); int intTotalFlowCnt = m_tblFlow.RowCount(null); ICursor pCursor = m_tblFlow.Search(null, false); IRow pRow = pCursor.NextRow(); IPoint pFromPt = null; IPoint pToPt = null; double dblFromX = 0, dblFromY = 0, dblToX = 0, dblToY = 0; IPolyline pPolyline = new PolylineClass(); cnt = 0; int intNonMatchedFlow = 0; while (pRow != null) { pfrmProgress.lblStatus.Text = "Create Flow Lines"; int intProgress = cnt * 100 / intTotalFlowCnt; pfrmProgress.bgWorker.ReportProgress(intProgress); string strOID = pRow.get_Value(intOIDIdx).ToString(); string strDID = pRow.get_Value(intDIDIdx).ToString(); RefSpatialInfo RefOInfo = lstRefInfo.Find(x => x.JoinID == strOID); RefSpatialInfo RefDInfo = lstRefInfo.Find(x => x.JoinID == strDID); if (RefOInfo == null || RefDInfo == null) { intNonMatchedFlow++; pRow = pCursor.NextRow(); cnt++; } else { dblFromX = RefOInfo.XCoor; dblFromY = RefOInfo.YCoor; dblToX = RefDInfo.XCoor; dblToY = RefDInfo.YCoor; pFromPt = new PointClass(); pToPt = new PointClass(); pFromPt.PutCoords(dblFromX, dblFromY); pToPt.PutCoords(dblToX, dblToY); pPolyline = new PolylineClass(); pPolyline.FromPoint = pFromPt; pPolyline.ToPoint = pToPt; IFeature pNewFeature = pFCOutput.CreateFeature(); pNewFeature.Shape = pPolyline; if (intCheckedFldCnt > 0) { for (int i = 0; i < intCheckedFldCnt; i++) { pNewFeature.set_Value(intAddFldIdsInFC[i], pRow.get_Value(intAddFldIdsInTable[i])); } } pNewFeature.Store(); pRow = pCursor.NextRow(); cnt++; } } //MessageBox.Show(intNonMatchedFlow.ToString()+" flow lines are not matched with the reference file"); //Check the message. 080516 HK } pfrmProgress.Close(); watch.Stop(); double dblTime = watch.ElapsedMilliseconds; MessageBox.Show("Run-time: " + dblTime.ToString()); DialogResult dialogResult = MessageBox.Show("Do you want to add the output data to the map?", "Add Data", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { IFeatureLayer pFeaturelayer = new FeatureLayer(); pFeaturelayer.Name = pFCOutput.AliasName; pFeaturelayer.FeatureClass = pFCOutput; m_pActiveView.FocusMap.AddLayer((ILayer)pFeaturelayer); } } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
public Task <bool> Update(IFeatureClass fClass, List <IFeature> features) { throw new NotImplementedException(); }
public Task <bool> Update(IFeatureClass fClass, IFeature feature) { throw new NotImplementedException(); }
public Task <bool> Insert(IFeatureClass fClass, IFeature feature) { return(Insert(fClass, new List <IFeature>(new IFeature[] { feature }))); }
private void LoadQueryResult() { IFeatureLayer featureLayer = this.layer as IFeatureLayer; if (featureLayer == null) { txb_Prompt.Visibility = Visibility.Visible; datagrid_Attribute.Visibility = Visibility.Collapsed; return; } IFeatureClass featureClass = featureLayer.FeatureClass; ILayerFields layerFields = featureLayer as ILayerFields; DataColumn dataColumn = null; DataTable dataTable = new DataTable(featureLayer.Name); DataTable dataTableResult = new DataTable(featureLayer.Name); string classFilter = string.Empty; for (int i = 0; i < layerFields.FieldCount; i++) { dataColumn = new DataColumn(layerFields.get_Field(i).Name); dataTable.Columns.Add(dataColumn); dataColumn = null; } IFeature feature = null; IQueryFilter queryFilter = new QueryFilterClass(); IFeatureCursor featureCursor; featureCursor = featureClass.Search(null, true); feature = featureCursor.NextFeature(); while (feature != null) { DataRow dataRow = dataTable.NewRow(); for (int i = 0; i < layerFields.FieldCount; i++) { if (layerFields.FindField(featureClass.ShapeFieldName) == i) { dataRow[i] = featureClass.ShapeType.ToString(); } else { dataRow[i] = feature.get_Value(i); } } dataTable.Rows.Add(dataRow); feature = featureCursor.NextFeature(); } classFilter = GetColumnCaption(dataTable); if (classFilter != string.Empty) { DataRow[] dataRows = dataTable.Select(classFilter + "=" + "'" + this.queryFilter + "'"); dataTableResult = dataTable.Clone(); foreach (var dataRow in dataRows) { dataTableResult.ImportRow(dataRow); } dataTableResult.Columns[classFilter].SetOrdinal(0); if (dataTable.Rows.Count > 0) { datagrid_Attribute.DataContext = dataTableResult; } else { txb_Prompt.Visibility = Visibility.Visible; datagrid_Attribute.Visibility = Visibility.Collapsed; return; } } else { if (dataTable.Rows.Count > 0) { datagrid_Attribute.DataContext = dataTable; } else { txb_Prompt.Visibility = Visibility.Visible; datagrid_Attribute.Visibility = Visibility.Collapsed; return; } } }
/// <summary> /// 获取两个要素类同名字段的索引的对应关系,存入键值对中 /// </summary> /// <param name="classOne">第一个要素类</param> /// <param name="classTwo">第二个要素类</param> /// <param name="withOutOidShape">去除OID和Shape字段的获取,默认true</param> /// <returns></returns> private static Dictionary <int, int> GetFieldIndexFromTwoClass(IFeatureClass classOne, IFeatureClass classTwo, bool withOutOidShape = true) { var dict = new Dictionary <int, int>();//key:字段在源要素类的索引;value:在目标要素类中的索引 var sourceFields = classOne.Fields; var tarFields = classTwo.Fields; var shapeFieldName = classOne.ShapeFieldName; var oidFieldName = classOne.OIDFieldName; for (var i = 0; i < sourceFields.FieldCount; i++) { var fieldName = sourceFields.get_Field(i).Name; if (withOutOidShape && (fieldName == shapeFieldName || fieldName == oidFieldName)) { continue; } var index = tarFields.FindField(fieldName); if (index > -1 && tarFields.get_Field(index).Editable) { dict.Add(i, index); } } return(dict); }
private bool CreateShpFile(List <ROIGeometry> geometryList, out string sShpFilePath) { bool result = false; string shpName = DateTime.Now.ToString("yyyyMMddhhmmss"); sShpFilePath = System.IO.Path.Combine(ConstDef.PATH_TEMP, shpName + ".shp"); try { if (!Directory.Exists(ConstDef.PATH_TEMP)) { Directory.CreateDirectory(ConstDef.PATH_TEMP); } IWorkspace workspace = EngineAPI.OpenWorkspace(ConstDef.PATH_TEMP, DataType.shp); if (workspace == null) { result = false; } else { IFields fields = this.CreateFields(); if (fields == null) { result = false; } IFeatureClass featureClass = this.CreateFeatureClass(workspace, shpName, fields, spatialReference); if (featureClass == null) { result = false; } try { int rowIndex = 0; foreach (ROIGeometry roi in geometryList) { IFeature pFeature = featureClass.CreateFeature(); pFeature.Shape = roi.geometry; pFeature.Store(); ITable pTable = pFeature.Table; if (pTable.RowCount(null) > 0) { IRow pRow = pTable.GetRow(rowIndex); pRow.set_Value(2, roi.name); pRow.set_Value(3, roi.id); pRow.set_Value(4, roi.color); pRow.Store(); } rowIndex++; //IFieldEdit field = feature as IField; } } catch (Exception ex) { Log.WriteLog(typeof(NeuralNet), ex); result = false; } finally { if (featureClass != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); } } } result = true; } catch (Exception ex) { Log.WriteLog(typeof(NeuralNet), ex); result = false; } return(result); }
public void ExportDatatoShape(string strFullName, ILayer m_pLayer) { ClsGDBDataCommon comm = new ClsGDBDataCommon(); string strPath = System.IO.Path.GetDirectoryName(strFullName); string strName = System.IO.Path.GetFileName(strFullName); //导出数据 IFeatureLayer pFtlayer = (IFeatureLayer)m_pLayer; IFeatureClass pFtClass = pFtlayer.FeatureClass; IFields pFields = pFtClass.Fields; //设置空间参考 ISpatialReference pSpatialRef; IGeoDataset pGeo = (IGeoDataset)pFtlayer; pSpatialRef = pGeo.SpatialReference; IFeatureClass pFtClassNew = comm.CreateShapefile(strPath, strName, pFields, pSpatialRef); if (pFtClassNew == null) { MessageBox.Show("创建shp文件失败!"); return; } ////////////////////////////////////////////////////////////////////////// IDataset dataset = (IDataset)pFtClassNew; IWorkspace workspace = dataset.Workspace; //Cast for an IWorkspaceEdit IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IFeatureBuffer featureBuffer; IFeatureCursor featureCursor = null; object featureOID; ////////////////////////////////////////////////////////////////////////// IFeature pFeature; long nCount; long nProcess = 0; ITable pTable = (ITable)m_pLayer; nCount = pTable.RowCount(null); IFeatureCursor pFtCursor = pFtlayer.Search(null, true); if (pFtCursor == null) { return; } pFeature = pFtCursor.NextFeature(); while (pFeature != null) { ////////////////////////////////////////////////////////////////////////// featureBuffer = pFtClassNew.CreateFeatureBuffer(); featureCursor = pFtClassNew.Insert(true); featureBuffer.Shape = pFeature.ShapeCopy; CopyFeatureField(pFeature, featureBuffer); featureOID = featureCursor.InsertFeature(featureBuffer); nProcess++; this.Text = string.Format("共有:{0}条数据,已处理:{1}条", nCount, nProcess); pFeature = pFtCursor.NextFeature(); } featureCursor.Flush(); workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); IFeatureLayer pOutFL = new FeatureLayerClass(); pOutFL.FeatureClass = pFtClassNew; pOutFL.Name = pFtClassNew.AliasName; }
//private static Collection FunGetFeaLyrCol(IMap iMap) //{ // throw new NotImplementedException(); //} /// <summary> /// 通过几何图形查询 /// </summary> /// <param name="blnSelect"></param> /// <param name="pGeometry"></param> /// <param name="pFeatCls"></param> /// <param name="pselecttype"></param> /// <param name="pFeatlayer"></param> /// <returns></returns> public static ClsMapLayer QueryByGeometry(bool blnSelect, IGeometry pGeometry, IFeatureClass pFeatCls, esriSelectionResultEnum pselecttype, IFeatureLayer pFeatlayer) { ClsMapLayer pQueryByGeometry = new ClsMapLayer(); pQueryByGeometry.FeatCls = pFeatCls; IDataset pDataset; pDataset = (IDataset)pFeatCls; IFeatureSelection pFeatSelection; ICursor pCursor = null; ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pGeometry; switch (pFeatCls.ShapeType) { case esriGeometryType.esriGeometryPoint: pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolyline: pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeometryPolygon: pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; default: pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelUndefined; break; } pSpatialFilter.GeometryField = pFeatCls.ShapeFieldName; ISpatialFilter pFilter; pFilter = pSpatialFilter; if (blnSelect == true) { pFeatSelection = (IFeatureSelection)pFeatlayer; pFeatSelection.SelectFeatures(pFilter, pselecttype, false); pQueryByGeometry.FeatLayer = pFeatlayer; pQueryByGeometry.FeatSelectionSet = pFeatSelection.SelectionSet as ISelectionSet2; pQueryByGeometry.FeatSelectionSet.Search(null, false, out pCursor); if (pCursor is IFeatureCursor) { pQueryByGeometry.FeatCur = (IFeatureCursor)pCursor; } return(pQueryByGeometry); } else { pFeatSelection = (IFeatureSelection)pFeatlayer; pFeatSelection.SelectFeatures(pFilter, pselecttype, false); //esriSelectionOption pSelectionOption; //pSelectionOption = pselecttype as esriSelectionResultEnum; pQueryByGeometry.FeatLayer = pFeatlayer; pQueryByGeometry.FeatSelectionSet = pQueryByGeometry.FeatCls.Select(pFilter, esriSelectionType.esriSelectionTypeHybrid, (esriSelectionOption)((int)pselecttype), pDataset.Workspace) as ISelectionSet2; pQueryByGeometry.FeatSelectionSet.Search(null, false, out pCursor); if (pCursor is IFeatureCursor) { pQueryByGeometry.FeatCur = (IFeatureCursor)pCursor; } return(pQueryByGeometry); } }
/// <summary> /// 以图层的方法插入相关元素 如经过站点、障碍点、障碍线、障碍多边形等 /// </summary> /// <param name="pNAContext">网络分析上下文</param> /// <param name="strNAClassName">Routes,Stops、Barriers、PolylineBarriers\PolygonBarriers</param> /// <param name="inputFeatuerClass">要素类</param> /// <param name="dSnapTolerance">阈值</param> public static void LoadNANetWorkLocations(INAContext pNAContext, string strNAClassName, IFeatureClass inputFeatuerClass, double dSnapTolerance) { INAClass pNAClass; INamedSet pNamedSet; pNamedSet = pNAContext.NAClasses; pNAClass = pNamedSet.get_ItemByName(strNAClassName) as INAClass; ISpatialFilter filer = new SpatialFilterClass(); filer.WhereClause = ""; int count = inputFeatuerClass.FeatureCount(filer as IQueryFilter); //删除已存在的元素 pNAClass.DeleteAllRows(); //创建NAClassLoader,设置捕捉容限值 INAClassLoader pNAClassLoader = new NAClassLoaderClass(); pNAClassLoader.Locator = pNAContext.Locator; if (dSnapTolerance > 0) { pNAClassLoader.Locator.SnapTolerance = dSnapTolerance; } pNAClassLoader.NAClass = pNAClass; //字段匹配 INAClassFieldMap pNAClassFieldMap = new NAClassFieldMapClass(); pNAClassFieldMap.CreateMapping(pNAClass.ClassDefinition, inputFeatuerClass.Fields); pNAClassLoader.FieldMap = pNAClassFieldMap; //加载要素类数据 int iRows = 0; int iRowsLocated = 0; IFeatureCursor pFeatureCursor = inputFeatuerClass.Search(null, true); pNAClassLoader.Load((ICursor)pFeatureCursor, null, ref iRows, ref iRowsLocated); ((INAContextEdit)pNAContext).ContextChanged(); }
/* * A function to populate a referenced Feature Class (fc) with the contents of a Google Maps Engine map layer */ protected void populateFCWithGoogleMapsEngineLayer(ref IFeatureClass fc, string mapId, string parentId, MapsEngine.DataModel.gme.MapLayer layer) { // create a new feature IFeature feature; log.Debug("Creating a feature for layer " + layer.id); // attempt to process the assets within a the layer try { // fetch the layer asset object from the API log.Debug("Fetching an asset object for the layer."); MapsEngine.DataModel.gme.Asset layerAsset = api.getAssetById(ext.getToken(), layer.id); // create a new feature log.Debug("Creating a new feature."); feature = fc.CreateFeature(); // Update the values for this feature feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_CustomerId_Name), mapId.Split("-".ToCharArray())[0]); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_CustomerId_Name + ": " + mapId.Split("-".ToCharArray())[0]); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetId_Name), layer.id); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetId_Name + ": " + layer.id); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_Name), mapId); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_Name + ": " + mapId); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name), layerAsset.type); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name + ": " + layerAsset.type); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetName_Name), layerAsset.name); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetName_Name + ": " + layerAsset.name); feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_Name), parentId); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_Name + ": " + parentId); // attempt to set the description object try { // set the layer description value (truncate if necessary) feature.set_Value(fc.FindField(Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_Name) , layerAsset.description.Length > 256 ? layerAsset.description.Substring(0, 252) + "..." : layerAsset.description); log.Debug(Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_Name + ": " + layerAsset.description); } catch (System.Exception ex) { // log warning log.Warn(ex); } // verify the layer has a bbox and has two valid points if (layerAsset.bbox != null && layerAsset.bbox.Count() == 4) { // deterine the maximum and minimum bounds of all layers within this map // 0=West, 1=South, 2=East, 3=North double XMAX = layerAsset.bbox[2]; log.Debug("XMAX: " + XMAX); double YMAX = layerAsset.bbox[3]; log.Debug("YMAX: " + YMAX); double XMIN = layerAsset.bbox[0]; log.Debug("XMIN: " + XMIN); double YMIN = layerAsset.bbox[1]; log.Debug("YMIN: " + YMIN); // determine the map extent based on the layers maximum extent IPoint pExtentNE = new Point(); pExtentNE.X = XMAX; pExtentNE.Y = YMAX; IPoint pExtentSW = new Point(); pExtentSW.X = XMIN; pExtentSW.Y = YMIN; IPoint pExtentNW = new Point(); pExtentNW.X = XMIN; pExtentNW.Y = YMAX; IPoint pExtentSE = new Point(); pExtentSE.X = XMAX; pExtentSE.Y = YMIN; // define the polygon bounding box (NE/SW) as a point collection IPointCollection pExtentPointCol = new Polygon(); pExtentPointCol.AddPoint(pExtentNE, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentSE, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentSW, Type.Missing, Type.Missing); pExtentPointCol.AddPoint(pExtentNW, Type.Missing, Type.Missing); // create a polygon, p, from the point collection, then close the polygon IPolygon pExtent = (IPolygon)pExtentPointCol; pExtent.Close(); // add the polygon, p, as the new feature's geometry if (pExtent != null) { // set the shape geometry log.Debug("Setting the feature's geometry as the polygon."); feature.Shape = pExtent; } else { // set the feature's goemetry as the default world log.Debug("Invalid spatial representation, setting feature goemtry as the world."); feature.Shape = worldPolygon; } } else { // the layer does not have spatial information log.Warn("Layer has no bbox information"); //feature.Shape = worldPolygon; } // Commit the new feature to fc log.Debug("Storing feature."); feature.Store(); } catch (Exception ex) { // log the warning log.Warn(ex); } }
// 公共方法 private void bindDataToCatalogTree(IConnectionInfo ci) { try { if (dsFactory == null) { dsFactory = new DataSourceFactory(); } IDataSource ds = dsFactory.OpenDataSource(ci); myTreeNode sourceNode = null; if (ci.ConnectionType == gviConnectionType.gviConnectionMySql5x) { sourceNode = new myTreeNode(ci.Database + "@" + ci.Server, ci); } else { sourceNode = new myTreeNode(ci.Database, ci); } this.treeView1.Nodes.Add(sourceNode); // 获取dataset string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } foreach (string setname in setnames) { IFeatureDataSet dataset = ds.OpenFeatureDataset(setname); TreeNode setNode = new TreeNode(setname, 1, 1); sourceNode.Nodes.Add(setNode); // 获取featureclass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames == null || fcnames.Length == 0) { continue; } foreach (string fcname in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(fcname); TreeNode fcNode = new TreeNode(fcname, 2, 2); setNode.Nodes.Add(fcNode); // 获取属性字段 IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } TreeNode fieldinfoNode = new TreeNode(fieldinfo.Name); fieldinfoNode.ContextMenuStrip = this.contextMenuStrip1; // 绑定右键菜单 fcNode.Nodes.Add(fieldinfoNode); } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } }
/// <summary> /// 代码图层检查---检查主函数 /// </summary> private void ExcuteLayerCheck(List <IDataset> LstDataset, string path) { Exception eError = null; string pClassifyName = GetClassifyName1(out eError); if (eError != null || pClassifyName == "") { return; } //用来存储MapControl上的图层的分类代码的相关信息 Dictionary <IFeatureClass, Dictionary <string, List <int> > > DicFea = new Dictionary <IFeatureClass, Dictionary <string, List <int> > >(); foreach (IDataset pDT in LstDataset) { IFeatureClass pFeatureClass = pDT as IFeatureClass; if (pFeatureClass == null) { return; } #region 首先检查Mapcontrol上的要素类是否具有分类代码这个字段 int index = -1; //分类代码索引 index = pFeatureClass.Fields.FindField(pClassifyName); if (index == -1) { //SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "不存在分类代码字段!"); //return; continue; } #endregion #region 将MapControl上的图层相关信息用字典存储起来 IFeatureCursor pFeaCursor = pFeatureClass.Search(null, false); if (pFeaCursor == null) { return; } IFeature pFeature = pFeaCursor.NextFeature(); if (pFeature == null) { continue; } while (pFeature != null) { string pGISID = pFeature.get_Value(index).ToString().Trim(); //分类代码 int pOID = pFeature.OID; //OID if (!DicFea.ContainsKey(pFeatureClass)) { //用来保存GISID和对应的OID Dictionary <string, List <int> > DicCode = new Dictionary <string, List <int> >(); List <int> LstOID = new List <int>(); LstOID.Add(pOID); DicCode.Add(pGISID, LstOID); DicFea.Add(pFeatureClass, DicCode); } else { if (!DicFea[pFeatureClass].ContainsKey(pGISID)) { List <int> LstOID = new List <int>(); LstOID.Add(pOID); DicFea[pFeatureClass].Add(pGISID, LstOID); } else { DicFea[pFeatureClass][pGISID].Add(pOID); } } pFeature = pFeaCursor.NextFeature(); } //释放CURSOR System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor); #endregion } //设置进度条 ProgressChangeEvent eInfo = new ProgressChangeEvent(); eInfo.Max = DicFea.Count; int pValue = 0; //int pMax = DicFea.Count; //GeoDataChecker._CheckForm.Invoke(new GeoDataChecker.IntiProgressBar(GeoDataChecker.intiaProgress), new object[] { pMax }); #region 进行分类代码检查 //遍历图层 foreach (KeyValuePair <IFeatureClass, Dictionary <string, List <int> > > FeaCls in DicFea) { IFeatureClass pFeaCls = FeaCls.Key; IDataset pDT = pFeaCls as IDataset; if (pDT == null) { return; } string pFeaClsNameStr = pDT.Name.Trim(); //要素类名称 if (pFeaClsNameStr.Contains(".")) { pFeaClsNameStr = pFeaClsNameStr.Substring(pFeaClsNameStr.IndexOf('.') + 1); } #region 检查分类代码与图层的对应关系 //遍历分类代码值,进行检查 foreach (KeyValuePair <string, List <int> > pGISIDItem in FeaCls.Value) { //分类代码的值 string ppGISID = pGISIDItem.Key; string sqlStr = "select * from GeoCheckCode where 分类代码 ='" + ppGISID + "'"; int pResult = CodeStandardizeCheck(sqlStr); //检查该分类代码是否存在于模板库中 if (pResult == -1) { return; } if (pResult == 1) { //分类代码存在 #region 检查分类代码与图层名的对应关系是否正确 //若能够找到该分类代码,则检查分类代码对应的图层名是否正确 string sqlStr2 = "select * from GeoCheckCode where 分类代码 ='" + ppGISID + "' and 图层='" + pFeaClsNameStr + "'"; int pResult2 = CodeStandardizeCheck(sqlStr2); //检查分类代码对应的图层名是否正确 if (pResult2 == -1) { return; } if (pResult2 == 1) { //对应关系正确 continue; } if (pResult2 == 0) { //对应关系不正确 #region 保存错误结果 //遍历该分类代码对应的要素OID集合 for (int m = 0; m < pGISIDItem.Value.Count; m++) { int pOID = pGISIDItem.Value[m]; IFeature pFeature = pFeaCls.GetFeature(pOID); IPoint pPoint = ModCommonFunction.GetPntOfFeature(pFeature); double pMapx = 0; // pPoint.X; double pMapy = 0; // pPoint.Y; if (pPoint != null) { pMapx = pPoint.X; pMapy = pPoint.Y; } //用来保存错误结果 List <object> ErrorLst = new List <object>(); ErrorLst.Add("批量检查"); ErrorLst.Add("代码图层检查"); ErrorLst.Add(path); ErrorLst.Add(enumErrorType.分类代码与图层名对应关系不正确.GetHashCode()); ErrorLst.Add("分类代码" + ppGISID + "与图层" + pFeaClsNameStr + "不对应!"); ErrorLst.Add(pMapx); //... ErrorLst.Add(pMapy); //... ErrorLst.Add(pFeaClsNameStr); ErrorLst.Add(pOID); ErrorLst.Add(""); ErrorLst.Add(-1); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } #endregion } #endregion } if (pResult == 0) { //分类代码不存在 #region 保存错误结果 //遍历该分类代码对应的要素OID集合 for (int m = 0; m < pGISIDItem.Value.Count; m++) { int pOID = pGISIDItem.Value[m]; double pMapx = 0.0; double pMapy = 0.0; //用来保存错误结果 List <object> ErrorLst = new List <object>(); ErrorLst.Add("批量检查"); ErrorLst.Add("代码图层检查"); ErrorLst.Add(path); ErrorLst.Add(enumErrorType.分类代码不存在.GetHashCode()); ErrorLst.Add("分类代码" + ppGISID + "不存在!"); ErrorLst.Add(pMapx); //... ErrorLst.Add(pMapy); //... ErrorLst.Add(pFeaClsNameStr); ErrorLst.Add(pOID); ErrorLst.Add(""); ErrorLst.Add(-1); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } #endregion } } #endregion //进度条加1 pValue++; eInfo.Value = pValue; //GeoDataChecker._CheckForm.Invoke(new GeoDataChecker.GEODataCheckerProgressShow(GeoDataChecker.GeoDataChecker_ProgressShow), new object[] { (object)GeoDataChecker._ProgressBarInner, eInfo }); GeoDataChecker.GeoDataChecker_ProgressShow((object)GeoDataChecker._ProgressBarInner, eInfo); //GeoDataChecker._CheckForm.Invoke(new GeoDataChecker.ChangeProgressBar(GeoDataChecker.changeProgress), new object[] {pValue}); } #endregion }
private void CutSelectedPolygon() { bool isSuccess = false; if (m_selectedFeature == null) { MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); m_toolPhase = ToolPhase.SelectFeature; return; } //在屏幕上绘制用于分割的线要素 IScreenDisplay screenDisplay = m_activeView.ScreenDisplay; ISimpleLineSymbol sym = new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = 255; color.Green = 128; color.Blue = 128; sym.Color = color; sym.Style = esriSimpleLineStyle.esriSLSSolid; sym.Width = 2; IRubberBand cutBand = new RubberLineClass(); IGeometry reshaprGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol); screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); screenDisplay.SetSymbol(sym as ISymbol); screenDisplay.DrawPolyline(reshaprGeometry); screenDisplay.FinishDrawing(); IFeatureClass featureClass = m_selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } //分割选择的面要素 if (reshaprGeometry.IsEmpty == true) { return; } try { IPolyline reshapePolyline, sourcePolyline = null; IPolygon4 polygon = null; IRing ring = null, innerRing = null, outRing = null; IPath reshapePath = null; IGeometryCollection pathCollection = null; IGeometry geometry = m_selectedFeature.Shape; switch (geometry.GeometryType) { case esriGeometryType.esriGeometryPolygon: bool outerSuccess = false, innerSuccess = false; IGeometryBag innerRingGeometryBag = null; IGeometryCollection innerRingGeometryCollection = null; reshapePolyline = reshaprGeometry as IPolyline; pathCollection = reshapePolyline as IGeometryCollection; //只可能产生一条polyline,直接写死 reshapePath = pathCollection.Geometry[0] as IPath; polygon = geometry as IPolygon4; IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag; IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection; for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++) { outRing = exteriorRingGeometryCollection.Geometry[i] as IRing; bool a = outRing.Reshape(reshapePath); outerSuccess = outerSuccess || a; innerRingGeometryBag = polygon.get_InteriorRingBag(outRing); innerRingGeometryCollection = innerRingGeometryBag as IGeometryCollection; for (int j = 0; j < innerRingGeometryCollection.GeometryCount; j++) { innerRing = innerRingGeometryCollection.Geometry[j] as IRing; bool b = innerRing.Reshape(reshapePath); innerSuccess = innerSuccess || b; } } isSuccess = innerSuccess || outerSuccess; break; case esriGeometryType.esriGeometryPolyline: sourcePolyline = geometry as IPolyline; reshapePolyline = reshaprGeometry as IPolyline; pathCollection = reshapePolyline as IGeometryCollection; //只可能产生一条polyline,直接写死 reshapePath = pathCollection.Geometry[0] as IPath; isSuccess = sourcePolyline.Reshape(reshapePath); break; } if (isSuccess) { workspaceEdit.StartEditOperation(); m_selectedFeature.Shape = geometry;//如果没加这句gdb无法编辑 m_selectedFeature.Store(); m_activeView.Refresh(); workspaceEdit.StopEditOperation(); } else { throw new Exception("重塑要素失败!"); } m_activeView.Refresh(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); m_toolPhase = ToolPhase.SelectFeature; }
private void ClassQuery(MajorClass mc, MajorClass mctemp, ISpatialFilter filter, IGeometry geo) { if (mc == null || filter == null || geo == null) { return; } string[] arrFc3DId = mc.Fc3D.Split(';'); if (arrFc3DId == null) { return; } foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible3D) { continue; } bool bHave = false; foreach (string fc3DId in arrFc3DId) { DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId); if (dffc == null) { continue; } FacilityClass facc = dffc.GetFacilityClass(); IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null || facc == null) { continue; } int geometryIndex = fc.GetFields().IndexOf("Geometry"); if (geometryIndex == -1) { continue; } filter.WhereClause = "GroupId = " + sc.GroupId; filter.SubFields = "Geometry"; int count = fc.GetCount(filter); if (count == 0) { continue; } int loop = (int)Math.Ceiling(count / 800.0); for (int k = 1; k <= loop; k++) { if (k == 1) { filter.ResultBeginIndex = 0; } else { filter.ResultBeginIndex = (k - 1) * 800; } filter.ResultLimit = 800; IFdeCursor cursor = fc.Search(filter, true); IRowBuffer row = null; while ((row = cursor.NextRow()) != null) { IModelPoint modelPoint = row.GetValue(0) as IModelPoint; if ((geo as IRelationalOperator2D).Contains2D(modelPoint)) { bHave = true; bHaveRes = true; break; } } if (bHave) { break; } } } if (bHave) { SubClass sctemp = new SubClass(sc.Name, sc.GroupId, sc.Parent); sctemp.Visible3D = sc.Visible3D; mctemp.SubClasses.Add(sctemp); } } }
/// <summary> /// 最短路径分析 /// </summary> /// <param name="mapControl">地图控件</param> /// <param name="gdbfileName">数据库文件</param> /// <param name="featureDatasetName">要素集名字</param> /// <param name="ndsName">网络数据集名字</param> /// <param name="featureClasses">参数要素类及其阈值,其中键值包括:Stops(路线经过结点),Barriers,PolylineBarriers,PolygonBarriers</param> /// <param name="isShowDataBase">是否显示网络数据集</param> /// <param name="isShowNalayer">是否显示网络分析图层</param> /// <param name="routeLayer">最近路线图层</param> public static bool Short_Path(AxMapControl mapControl, string gdbfileName, string featureDatasetName, string ndsName, IDictionary <string, DecorateRouteFeatureClass> featureClasses, bool isShowDataBase, bool isShowNalayer, ref ILayer routeLayer) { //首先判断输入的参数要素类是否合法 if (!FeatureClassKeyIsRight(featureClasses)) { throw new Exception("参数字典错误"); } // mapControl.ClearLayers(); //打开工作空间 IFeatureWorkspace pFeatureWorkspace = OpenWorkspace(gdbfileName) as IFeatureWorkspace; if (pFeatureWorkspace == null) { return(false); } //获取网络数据集 INetworkDataset pNetworkDataset = OpenNetworkDataset(pFeatureWorkspace as IWorkspace, featureDatasetName, ndsName); if (pNetworkDataset == null) { Debug.Print("无法获取网络数据集"); return(false); } //获取网络分析上下文 INAContext pNAContext = CreateNAContext(pNetworkDataset); //打开节点图层 一般和网络数据集放置在一起 名称是xxx_Junctions IFeatureClass pVertexFC = pFeatureWorkspace.OpenFeatureClass(ndsName + "_Junctions"); ILayer pLayer = null; // 显示网络数据集图层 if (isShowDataBase) { INetworkLayer pNetworkLayer = new NetworkLayerClass(); pNetworkLayer.NetworkDataset = pNetworkDataset; pLayer = pNetworkLayer as ILayer; pLayer.Name = "网络数据集"; mapControl.AddLayer(pLayer, 0); } //创建网络分析图层 INALayer naLayer = pNAContext.Solver.CreateLayer(pNAContext); //显示网络分析图层 if (isShowNalayer) { pLayer = naLayer as ILayer; pLayer.Name = pNAContext.Solver.DisplayName; pLayer.SpatialReference = mapControl.SpatialReference; mapControl.AddLayer(pLayer, 0); IActiveView pActiveView = mapControl.ActiveView; IMap pMap = pActiveView.FocusMap; IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer; mapControl.Refresh(); } INASolver naSolver = pNAContext.Solver; //插入相关数据 foreach (var value in featureClasses) { LoadNANetWorkLocations(pNAContext, value.Key, value.Value.FeatureClass, value.Value.SnapTolerance); } //插入经过点 //LoadNANetWorkLocations(pNAContext,"Stops", stopFeatureClass, 30); //插入障碍点 // LoadNANetWorkLocations(pNAContext, "Barriers", barriesFeatureClass, 30); IGPMessages gpMessages = new GPMessagesClass(); // SetSolverSettings(pNAContext); //寻找最短路径 try { pNAContext.Solver.Solve(pNAContext, gpMessages, new CancelTrackerClass()); routeLayer = naLayer.get_LayerByNAClassName("Routes"); } catch (Exception e) { Debug.Print("无法找到最短路径:" + e.Message); return(false); } mapControl.Refresh(); if (gpMessages != null) { for (int i = 0; i < gpMessages.Count; i++) { switch (gpMessages.GetMessage(i).Type) { case esriGPMessageType.esriGPMessageTypeError: Debug.Print("错误 " + gpMessages.GetMessage(i).ErrorCode.ToString() + " " + gpMessages.GetMessage(i).Description); break; case esriGPMessageType.esriGPMessageTypeWarning: Debug.Print("警告 " + gpMessages.GetMessage(i).Description); break; default: Debug.Print("信息 " + gpMessages.GetMessage(i).Description); break; } } } return(true); }
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 }
public Task <bool> Delete(IFeatureClass fClass, string where) { throw new NotImplementedException(); }
async internal Task <IMongoCollection <Json.GeometryDocument> > GetFeatureCollection(IFeatureClass fc) { var database = GetMongoDatabase(); var collectionName = fc.Name.ToFeatureClassCollectionName(); if (!await CollectionExistsAsync(database, collectionName)) { return(await CreateSpatialCollection(database, collectionName)); } return(database.GetCollection <Json.GeometryDocument>(collectionName)); }
protected override void OnClick() { try { List <ESRI.ArcGIS.Geometry.IPoint> Flags; List <ESRI.ArcGIS.Geometry.IPoint> Barriers; IWorkspace pWS; IFields pFields; IPoint pNPt; Globals.getFlagsBarriers(ArcMap.Application, out Flags, out Barriers); // Open the Workspace if ((pWS = Globals.GetInMemoryWorkspaceFromTOC(ArcMap.Document.FocusMap)) == null) { pWS = Globals.CreateInMemoryWorkspace(); } pFields = Globals.createFeatureClassFields(ArcMap.Document.FocusMap.SpatialReference, esriGeometryType.esriGeometryPoint); IFeatureClass pFlagsFC = Globals.createFeatureClassInMemory(A4LGSharedFunctions.Localizer.GetString("ExportFlagsName"), pFields, pWS, esriFeatureType.esriFTSimpleJunction); IFeatureClass pBarriersFC = Globals.createFeatureClassInMemory(A4LGSharedFunctions.Localizer.GetString("ExportBarriersName"), pFields, pWS, esriFeatureType.esriFTSimpleJunction); IFeatureCursor pntInsertCurs = pFlagsFC.Insert(true); IFeatureBuffer pFBuf; IFeature pFeat; foreach (ESRI.ArcGIS.Geometry.IPoint pnt in Flags) // Loop through List with foreach { pFBuf = pFlagsFC.CreateFeatureBuffer(); pFeat = (IFeature)pFBuf; pNPt = new ESRI.ArcGIS.Geometry.PointClass(); pNPt.X = pnt.X; pNPt.Y = pnt.Y; pFeat.Shape = pNPt; pntInsertCurs.InsertFeature(pFBuf); } pntInsertCurs = pBarriersFC.Insert(true); foreach (ESRI.ArcGIS.Geometry.IPoint pnt in Barriers) // Loop through List with foreach { pFBuf = pBarriersFC.CreateFeatureBuffer(); pFeat = (IFeature)pFBuf; pNPt = new ESRI.ArcGIS.Geometry.PointClass(); pNPt.X = pnt.X; pNPt.Y = pnt.Y; pFeat.Shape = pNPt; pntInsertCurs.InsertFeature(pFBuf); } IFeatureLayer pFlagsLayer = new FeatureLayerClass(); pFlagsLayer.FeatureClass = pFlagsFC; pFlagsLayer.Name = A4LGSharedFunctions.Localizer.GetString("ExportFlagsName"); IFeatureLayer pBarriersLayer = new FeatureLayerClass(); pBarriersLayer.FeatureClass = pBarriersFC; pBarriersLayer.Name = A4LGSharedFunctions.Localizer.GetString("ExportBarriersName"); ArcMap.Document.FocusMap.AddLayer(pFlagsLayer); ArcMap.Document.FocusMap.AddLayer(pBarriersLayer); ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } }
public Task <bool> Delete(IFeatureClass fClass, int oid) { throw new NotImplementedException(); }