private IFeatureLayer MakePointFeatureLayer(FusionTable ft, List <RowPoint> lstGeomsPoint) { IFeatureLayer pPointLayer = new FeatureLayerClass(); pPointLayer.FeatureClass = MakeInMemoryFeatureClass(ft, esriGeometryType.esriGeometryPoint); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pPointLayer.Search(null, false); pFCurOutPoints = pPointLayer.FeatureClass.Insert(true); IFeatureBuffer pFBuffer = pPointLayer.FeatureClass.CreateFeatureBuffer(); IPoint ppoint; foreach (RowPoint pt in lstGeomsPoint) { ppoint = new PointClass(); ppoint.X = pt.geometry.coordinates[0]; ppoint.Y = pt.geometry.coordinates[1]; pFBuffer.Shape = ppoint; //for (int i = 0; i <= pFBuffer.Fields.FieldCount - 1; i++) //{ // string g = pFBuffer.Fields.get_Field(i).Name; // foreach (string col in ft.columns) // { // if (col == pFBuffer.Fields.get_Field(i).Name) // { // pFBuffer.set_Value(pFBuffer.Fields.FindField(col), ft.rows[i]); // } // } //} pFCurOutPoints.InsertFeature(pFBuffer); } pPointLayer.Name = "FusionTablePoint"; return(pPointLayer); }
private IFeatureLayer MakeLineFeatureLayer(FusionTable ft, List <RowLine> lstGeomsLine) { IFeatureLayer pLineLayer = new FeatureLayerClass(); pLineLayer.FeatureClass = MakeInMemoryFeatureClass(ft, esriGeometryType.esriGeometryPolyline); //Set up the Outpoints cursor IFeatureCursor pFCurOutLine = pLineLayer.Search(null, false); pFCurOutLine = pLineLayer.FeatureClass.Insert(true); IFeatureBuffer pFBuffer = pLineLayer.FeatureClass.CreateFeatureBuffer(); IPointCollection pNewLinePointColl = null; IPoint ppoint; foreach (RowLine line in lstGeomsLine) { pNewLinePointColl = new PolylineClass(); foreach (List <double> pt in line.geometry.coordinates) { ppoint = new PointClass(); ppoint.X = pt[0]; ppoint.Y = pt[1]; pNewLinePointColl.AddPoint(ppoint); } pFBuffer.Shape = pNewLinePointColl as PolylineClass; pFCurOutLine.InsertFeature(pFBuffer); } pLineLayer.Name = "FusionTableLine"; return(pLineLayer); }
private IFeatureLayer MakePolygonFeatureLayer(FusionTable ft, List <RowPolygon> lstGeomsPolygon) { IFeatureLayer pPolyLayer = new FeatureLayerClass(); pPolyLayer.FeatureClass = MakeInMemoryFeatureClass(ft, esriGeometryType.esriGeometryPolygon); //Set up the Outpoints cursor IFeatureCursor pFCurOutLine = pPolyLayer.Search(null, false); pFCurOutLine = pPolyLayer.FeatureClass.Insert(true); IFeatureBuffer pFBuffer = pPolyLayer.FeatureClass.CreateFeatureBuffer(); IPointCollection pointCollection = null; IPoint ppoint; foreach (RowPolygon poly in lstGeomsPolygon) { pointCollection = new PolygonClass(); foreach (List <double> pt in poly.geometry.coordinates[0]) { ppoint = new PointClass(); ppoint.X = pt[0]; ppoint.Y = pt[1]; pointCollection.AddPoint(ppoint); } pFBuffer.Shape = pointCollection as PolygonClass; pFCurOutLine.InsertFeature(pFBuffer); } pPolyLayer.Name = "FusionTablePolygon"; return(pPolyLayer); }
//读取GDB数据 public List <ILayer> ReadLayerFromGDB(List <string> filePathList) { List <ILayer> layerList = new List <ILayer>(); string waterMarker = "1111100000"; if (filePathList.Count == 0) { return(null); } else { foreach (string path in filePathList) { IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTAny) as IEnumDataset; pEnumDataset.Reset(); IDataset pDataset = pEnumDataset.Next(); IWorkspace workspace = pDataset.Workspace; IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); while (pDataset is IFeatureClass) { IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name); pFeatureLayer.Name = pDataset.Name; //添加嵌入水印的功能 List <IPoint> points = new List <IPoint>(); if (pFeatureLayer != null && pFeatureLayer.FeatureClass.FeatureCount(null) != 1) { IFeatureCursor featureCursor = pFeatureLayer.Search(null, false); IFeature pFeature = featureCursor.NextFeature();//遍历查询结果 while (pFeature != null) { IPointCollection pointColl = null; switch (pFeature.Shape.GeometryType) { case esriGeometryType.esriGeometryPoint: (pFeature.Shape as Point).PutCoords(0, 0); points.Add(pFeature.Shape as Point); break; case esriGeometryType.esriGeometryMultipoint: points.Add(pFeature.Shape as Point); break; case esriGeometryType.esriGeometryLine: case esriGeometryType.esriGeometryPolyline: pointColl = (pFeature.Shape) as IPointCollection; int n = 10; if (pointColl.PointCount > 10) { n = 10; } else { n = pointColl.PointCount; } for (int m = 0; m < pointColl.PointCount; m++) { IPoint point = pointColl.get_Point(m); point.X = 4000000.00000001; (pFeature.Shape as IPointCollection).UpdatePoint(m, point); } pFeature.Shape = (IGeometry)pointColl; pFeature.Store(); break; case esriGeometryType.esriGeometryPolygon: pointColl = (pFeature.Shape) as IPointCollection; int k = 10; if (pointColl.PointCount > 10) { k = 10; } else { k = pointColl.PointCount; } for (int m = 0; m < pointColl.PointCount; m++) { IPoint point = pointColl.get_Point(m); point.X = 4000000.00000001; (pFeature.Shape as IPointCollection).UpdatePoint(m, point); } pFeature.Shape = (IGeometry)pointColl; pFeature.Store(); break; default: break; } if (pointColl == null) { continue; } pFeature = featureCursor.NextFeature(); } ILayer pLayer = pFeatureLayer as ILayer; layerList.Add(pFeatureLayer as ILayer); } pDataset = pEnumDataset.Next(); } Marshal.ReleaseComObject(pWorkspaceFactory); } return(layerList); } }
//读取水印时参考这个 public List <ILayer> ReadLayerWATERMARKERFromGDB(List <string> filePathList) { List <ILayer> layerList = new List <ILayer>(); string waterMarker = "1111100000"; if (filePathList.Count == 0) { return(null); } else { foreach (string path in filePathList) { IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset; pEnumDataset.Reset(); IDataset pDataset = pEnumDataset.Next(); while (pDataset is IFeatureClass) { //using(ESRI.ArcGIS.ADF.ComReleaser comReleaser = new ESRI.ArcGIS.ADF.ComReleaser()) IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name); pFeatureLayer.Name = pDataset.Name; //添加嵌入水印的功能 List <IPoint> points = new List <IPoint>(); if (pFeatureLayer != null && pFeatureLayer.FeatureClass.FeatureCount(null) != 1) { IFeatureCursor featureCursor = pFeatureLayer.Search(null, false); IFeature pFeature = featureCursor.NextFeature();//遍历查询结果 while (pFeature != null) { IPointCollection pointColl = null; switch (pFeature.Shape.GeometryType) { case esriGeometryType.esriGeometryPoint: points.Add(pFeature.Shape as Point); break; case esriGeometryType.esriGeometryMultipoint: points.Add(pFeature.Shape as Point); break; case esriGeometryType.esriGeometryLine: case esriGeometryType.esriGeometryPolyline: pointColl = (pFeature.Shape) as IPointCollection; break; case esriGeometryType.esriGeometryPolygon: case esriGeometryType.esriGeometryEnvelope: pointColl = (pFeature.Shape) as IPointCollection; break; default: break; } if (pointColl == null) { continue; } for (int k = 0; k < pointColl.PointCount; k++) { points.Add(pointColl.get_Point(k)); } pFeature = featureCursor.NextFeature(); } } Complex[] pointComplex = new Complex[points.Count]; //复数序列 for (int j = 0; j < points.Count; j++) { pointComplex[j] = new Complex(points[j].X, points[j].Y); } ILayer pLayer = pFeatureLayer as ILayer; layerList.Add(pFeatureLayer as ILayer); pDataset = pEnumDataset.Next(); } } return(layerList); } }
public void ExtractPointData(string sLineLayer, string sRasterLayer, double dblInterval, string strFileName) { try { strSaveFile = strFileName; IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IFeatureLayer pLineLayer = FindLayer(sLineLayer) as IFeatureLayer; IRasterLayer pRasterLayer = FindLayer(sRasterLayer) as IRasterLayer; //IFeatureLayer pPointLayer = FindLayer(sPointLayer) as IFeatureLayer; IFeatureLayer pPointLayer = new FeatureLayerClass(); pPointLayer.FeatureClass = MakePointFC(); //pPointLayer.Name = "Points"; // ArcMap.Document.ActiveView.FocusMap.AddLayer(pPointLayer); //get the Workspace from the IDataset interface on the feature class IDataset dataset = (IDataset)pLineLayer.FeatureClass; IWorkspace workspace = dataset.Workspace; //Cast for an IWorkspaceEdit IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; //Start an edit session and operation workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1); pProgressDialog.ShowDialog(); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pPointLayer.Search(null, false); pFCurOutPoints = pPointLayer.FeatureClass.Insert(true); //Set up the LineLayer Cursor IFeatureCursor pFCur = pLineLayer.Search(null, false); IFeature pLineFeature = pFCur.NextFeature(); IFeatureBuffer pFBuffer = pPointLayer.FeatureClass.CreateFeatureBuffer(); ICurve pCurve; double dlbProcessedLength = 0; double dblFCTotalLength = 0; int p = 0; while (pLineFeature != null) { pProgressDialog.Description = "Calculating line segment " + p.ToString() + " of: " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); //create startpoint pCurve = pLineFeature.Shape as ICurve; pFBuffer.Shape = pCurve.FromPoint; pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), 0); pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), pCurve.FromPoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), pCurve.FromPoint.Y); pFCurOutPoints.InsertFeature(pFBuffer); double dblTotalDistance = pCurve.Length; dlbProcessedLength = dblInterval; IConstructPoint contructionPoint; IPoint ppoint; while (dlbProcessedLength <= dblTotalDistance) { contructionPoint = new PointClass(); contructionPoint.ConstructAlong(pCurve, esriSegmentExtension.esriNoExtension, dlbProcessedLength, false); ppoint = new PointClass(); ppoint = contructionPoint as IPoint; pFBuffer.Shape = ppoint; //dblFCTotalLength += dblInterval; pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dlbProcessedLength, 4)); pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), ppoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), ppoint.Y); pFCurOutPoints.InsertFeature(pFBuffer); dlbProcessedLength += dblInterval; pStepProgressor.Step(); } dblFCTotalLength += dblInterval; p++; pLineFeature = pFCur.NextFeature(); } //cleanup pFCurOutPoints.Flush(); pFCur.Flush(); //Stop editing workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); Extract(pRasterLayer, pPointLayer); pProgressDialog.HideDialog(); pmxdoc.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }
public void CalculatePoints(string sLineLayer, string sShorelineLayer, string sDepthLayer, double dblInterval, string ShoreDepthField, string DepthPointDepthField) { try { IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IFeatureLayer pDepthSoundings = FindLayer(pmap, sDepthLayer) as IFeatureLayer; IFeatureLayer pShorelineLayer = FindLayer(pmap, sShorelineLayer) as IFeatureLayer; IFeatureLayer pLineLayer = FindLayer(pmap, sLineLayer) as IFeatureLayer; //IFeatureLayer pOutpoints = FindLayer(pmap, sOutpoints) as IFeatureLayer; IFeatureLayer pConnectingLines = FindLayer(pmap, "ConnectingLines") as IFeatureLayer; IFeatureLayer pShorePoints = FindLayer(pmap, "ShorePoints") as IFeatureLayer; IFeatureLayer pOutpoints = new FeatureLayerClass(); pOutpoints.FeatureClass = MakePointFC(); pOutpoints.Name = "Output Points"; ArcMap.Document.ActiveView.FocusMap.AddLayer(pOutpoints); //AddField(pOutpoints, "Distance"); //AddField(pOutpoints, "Elevation"); IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1); pProgressDialog.ShowDialog(); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pOutpoints.Search(null, false); pFCurOutPoints = pOutpoints.FeatureClass.Insert(true); //Set up the LineLayer Cursor IFeatureCursor pFCur = pLineLayer.Search(null, false); IFeature pLineFeature = pFCur.NextFeature(); IFeatureBuffer pFBuffer = pOutpoints.FeatureClass.CreateFeatureBuffer(); ICurve pCurve; IPoint ppoint; int iLineProgressCount = 1; double dblDistance = 0; double dblTotalDistanceCalculated = 0; int iNumIntervals = 0; double dblElevationDiff = 0; double dblElevationInterval = 0; double dblElevation = 0; double dlbStartElevation = 0; double dblEndElevation = 0; pProgressDialog.Description = "Generating points for Line: " + iLineProgressCount + " of " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); while (pLineFeature != null) { pCurve = pLineFeature.Shape as ICurve; pCurve.Project(pmap.SpatialReference); //Get the Starting Elevation from the closest depth point dlbStartElevation = GetStartElevation(pDepthSoundings, pLineLayer, pLineFeature, DepthPointDepthField); //The Elevation for the first run IS the start elevation dblElevation = dlbStartElevation; //Get the ending elevation from the shoreline dblEndElevation = GetFinalElevation(pShorelineLayer, pLineLayer, pLineFeature, ShoreDepthField); //number of line segments based on the user's interval iNumIntervals = Convert.ToInt32(pCurve.Length / dblInterval); dblElevationDiff = Math.Abs(dblEndElevation - dlbStartElevation); //The calculated elevation interval to step up each time dblElevationInterval = dblElevationDiff / iNumIntervals; ppoint = new PointClass(); //loop until the distance calculated hits the line length while (dblTotalDistanceCalculated <= pCurve.Length) { pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), dblDistance); pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), dblElevation); //this code set the point on the line at a distance pCurve.QueryPoint(0, dblDistance, false, ppoint); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), ppoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), ppoint.Y); //reCalc the new distance and elevation values for the next iteration dblDistance = dblDistance + dblInterval; dblElevation = dblElevation + dblElevationInterval; dblTotalDistanceCalculated = dblTotalDistanceCalculated + dblInterval; //Insert the feature into the featureclass pFBuffer.Shape = ppoint; pFCurOutPoints.InsertFeature(pFBuffer); } //Reset the distance values back to 0 for the next feature dblDistance = 0; dblTotalDistanceCalculated = 0; pLineFeature = pFCur.NextFeature(); pStepProgressor.Step(); pProgressDialog.Description = "Generating points for Line: " + iLineProgressCount + " of " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); iLineProgressCount++; } //cleanup pFCurOutPoints.Flush(); pFCur.Flush(); pProgressDialog.HideDialog(); pmxdoc.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }
public void GeneratePoints2(string sLineLayer, string sDepthPointsLayer, double dblInterval, string strDepthField) { try { IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IFeatureLayer pDepthSoundings = FindLayer(pmap, sDepthPointsLayer) as IFeatureLayer; IFeatureLayer pLineLayer = FindLayer(pmap, sLineLayer) as IFeatureLayer; IFeatureLayer pOutpoints = new FeatureLayerClass(); pOutpoints.FeatureClass = MakePointFC(); pOutpoints.Name = "Output Points"; ArcMap.Document.ActiveView.FocusMap.AddLayer(pOutpoints); IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1); pProgressDialog.ShowDialog(); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pOutpoints.Search(null, false); pFCurOutPoints = pOutpoints.FeatureClass.Insert(true); //Set up the LineLayer Cursor IFeatureCursor pFCur = pLineLayer.Search(null, false); IFeature pLineFeature = pFCur.NextFeature(); IFeatureBuffer pFBuffer = pOutpoints.FeatureClass.CreateFeatureBuffer(); ICurve pCurve; IPoint ppoint; int iLineProgressCount = 1; double dblDistance = 0; double dblTotalDistanceCalculated = 0; double iNumIntervals = 0; double dblElevationDiff = 0; double dblElevationInterval = 0; double dblElevation = 0; double dlbStartElevation = 0; double dblEndElevation = 0; pProgressDialog.Description = "Generating points for Line: " + iLineProgressCount + " of " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); while (pLineFeature != null) { int iStartVertex = 0; int iEndVertex = 1; //Get the vertices of the line feature IPointCollection4 pPointColl = pLineFeature.Shape as IPointCollection4; //loop thru the vertices for (int i = 0; i <= pPointColl.PointCount - 1; i++) { IPoint pStartPoint = pPointColl.get_Point(iStartVertex); IPoint pEndPoint = pPointColl.get_Point(iEndVertex); //Make an intermediate line segment between each set of vertices IPath pPath = MakePath(pStartPoint, pEndPoint); //Get the starting elevation from the depth point layer dlbStartElevation = GetPointElevation(pDepthSoundings, pLineLayer, pStartPoint, strDepthField); dblElevation = dlbStartElevation; IPointCollection pPointForPath = null; //Get the ending elevation from the next vertex pEndPoint = pPointColl.get_Point(iEndVertex); dblEndElevation = GetPointElevation(pDepthSoundings, pLineLayer, pEndPoint, strDepthField); //If the returned elevation is 0, then there is no coincident depth point, move to the next vertex for your endpoint if (dblEndElevation == 0) { //IPointCollection reshapePath = new PathClass(); object missing = Type.Missing; pPointForPath = new PathClass(); pPointForPath.AddPoint(pStartPoint, ref missing, ref missing); while (dblEndElevation == 0) { pEndPoint = pPointColl.get_Point(iEndVertex); dblEndElevation = GetPointElevation(pDepthSoundings, pLineLayer, pEndPoint, strDepthField); pPointForPath.AddPoint(pEndPoint, ref missing, ref missing); //pLineSegment.Reshape(reshapePath as IPath); if (dblEndElevation != 0) { break; } iEndVertex++; } } if (pPointForPath != null) { pPath = pPointForPath as IPath; } //number of line segments based on the user's interval iNumIntervals = Convert.ToDouble(pPath.Length / dblInterval); dblElevationDiff = dblEndElevation - dlbStartElevation; //The calculated elevation interval to step up each time dblElevationInterval = dblElevationDiff / iNumIntervals; ppoint = new PointClass(); while (dblTotalDistanceCalculated <= pPath.Length) { pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dblDistance, 4)); pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), Math.Round(dblElevation, 4)); //this code set the point on the line at a distance pPath.QueryPoint(0, dblDistance, false, ppoint); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), ppoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), ppoint.Y); //reCalc the new distance and elevation values for the next iteration dblDistance = dblDistance + dblInterval; dblTotalDistanceCalculated = dblTotalDistanceCalculated + dblInterval; //Insert the feature into the featureclass pFBuffer.Shape = ppoint; if (!IsPointCoincident(ppoint, pOutpoints)) { pFCurOutPoints.InsertFeature(pFBuffer); } if (dblTotalDistanceCalculated >= pPath.Length) { break; } dblElevation = dblElevation + dblElevationInterval; } //start the next line segment at the end of last one iStartVertex = iEndVertex; //look to the next vertex for the new ending point iEndVertex++; if (iEndVertex == pPointColl.PointCount) { ////if its the last vertex of the last line, add a point //pFBuffer.Shape = pPath.ToPoint; //pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); //pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dblDistance, 4)); //pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), Math.Round(dblElevation, 4)); //pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), pPath.ToPoint.X); //pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), pPath.ToPoint.Y); //pFCurOutPoints.InsertFeature(pFBuffer); //Reset the distance values back to 0 for the next feature dblDistance = 0; dblTotalDistanceCalculated = 0; pStepProgressor.Step(); iLineProgressCount++; pPath.SetEmpty(); break; } //Reset the distance values back to 0 for the next feature dblDistance = 0; dblTotalDistanceCalculated = 0; //pLineFeature = pFCur.NextFeature(); pStepProgressor.Step(); //pProgressDialog.Description = "Generating points for Line: " + iLineProgressCount + " of " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); iLineProgressCount++; pPath.SetEmpty(); } pLineFeature = pFCur.NextFeature(); } //cleanup pFCurOutPoints.Flush(); pFCur.Flush(); pProgressDialog.HideDialog(); pmxdoc.ActiveView.Refresh(); } catch (Exception ex) { } }
public void ceshiSelect(string shpFileName, string shpFilePath) { try { IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(shpFilePath, 0); IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(shpFileName); //使要素处于编辑状态 IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IDataset dataset = (IDataset)pFeatureClass; //ITable tb = (ITable)pFeatureClass; IWorkspace workspace = dataset.Workspace; IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; //workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); //CopyFeatureClass(gp, selectfeature(pFeatureLayer,"VALUE>5"),@"D:\测试\searchResult.shp"); //selectfeature(pFeatureLayer, "VALUE>5"); IQueryFilter pQueryFilter = new QueryFilterClass(); IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pQueryFilter, true); IFeature pFeature = pFeatureCursor.NextFeature(); // while (pFeature != null)//遍历线图层的name,将线图层中的name和点图层中的lineName加入选择集并对两个选择集进行near,勾选location生成nearX和nearY // { IFeatureSelection featureSelection = pFeatureLayer as IFeatureSelection; //string name = pFeature.get_Value(2).ToString();//线图层的name字段 pQueryFilter.WhereClause = "VALUE>5";// string.Format("name='{0}'", name); featureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);//选择线路名为name的线要素 IFeatureClass pFeatureclass = featureSelection.SelectionSet as IFeatureClass; //这里这样写是不时就选好了那个WhereClause 另一个也是这么执行的 就是想当于你选好的 输入同的参数选择不同的 你稍等我下 //pFeature = pFeatureCursor.NextFeature(); // } ESRI.ArcGIS.DataManagementTools.CopyFeatures copyFeatures = new CopyFeatures(); copyFeatures.in_features = pFeatureclass;// pFeatureLayer.FeatureClass; copyFeatures.out_feature_class = @"D:\测试\searchResult3.shp"; gp.OverwriteOutput = true; gp.Execute(copyFeatures, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private IFeatureLayer MakePolygonFeatureLayer(FusionTable ft, List<RowPolygon> lstGeomsPolygon) { IFeatureLayer pPolyLayer = new FeatureLayerClass(); pPolyLayer.FeatureClass = MakeInMemoryFeatureClass(ft, esriGeometryType.esriGeometryPolygon); //Set up the Outpoints cursor IFeatureCursor pFCurOutLine = pPolyLayer.Search(null, false); pFCurOutLine = pPolyLayer.FeatureClass.Insert(true); IFeatureBuffer pFBuffer = pPolyLayer.FeatureClass.CreateFeatureBuffer(); IPointCollection pointCollection = null; IPoint ppoint; foreach (RowPolygon poly in lstGeomsPolygon) { pointCollection = new PolygonClass(); foreach (List<double> pt in poly.geometry.coordinates[0]) { ppoint = new PointClass(); ppoint.X = pt[0]; ppoint.Y = pt[1]; pointCollection.AddPoint(ppoint); } pFBuffer.Shape = pointCollection as PolygonClass; pFCurOutLine.InsertFeature(pFBuffer); } pPolyLayer.Name = "FusionTablePolygon"; return pPolyLayer; }
private IFeatureLayer MakePointFeatureLayer(FusionTable ft, List<RowPoint> lstGeomsPoint) { IFeatureLayer pPointLayer = new FeatureLayerClass(); pPointLayer.FeatureClass = MakeInMemoryFeatureClass(ft, esriGeometryType.esriGeometryPoint); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pPointLayer.Search(null, false); pFCurOutPoints = pPointLayer.FeatureClass.Insert(true); IFeatureBuffer pFBuffer = pPointLayer.FeatureClass.CreateFeatureBuffer(); IPoint ppoint; foreach (RowPoint pt in lstGeomsPoint) { ppoint = new PointClass(); ppoint.X = pt.geometry.coordinates[0]; ppoint.Y = pt.geometry.coordinates[1]; pFBuffer.Shape = ppoint; //for (int i = 0; i <= pFBuffer.Fields.FieldCount - 1; i++) //{ // string g = pFBuffer.Fields.get_Field(i).Name; // foreach (string col in ft.columns) // { // if (col == pFBuffer.Fields.get_Field(i).Name) // { // pFBuffer.set_Value(pFBuffer.Fields.FindField(col), ft.rows[i]); // } // } //} pFCurOutPoints.InsertFeature(pFBuffer); } pPointLayer.Name = "FusionTablePoint"; return pPointLayer; }
private IFeatureLayer MakeLineFeatureLayer(FusionTable ft, List<RowLine> lstGeomsLine) { IFeatureLayer pLineLayer = new FeatureLayerClass(); pLineLayer.FeatureClass = MakeInMemoryFeatureClass(ft, esriGeometryType.esriGeometryPolyline); //Set up the Outpoints cursor IFeatureCursor pFCurOutLine = pLineLayer.Search(null, false); pFCurOutLine = pLineLayer.FeatureClass.Insert(true); IFeatureBuffer pFBuffer = pLineLayer.FeatureClass.CreateFeatureBuffer(); IPointCollection pNewLinePointColl = null; IPoint ppoint; foreach (RowLine line in lstGeomsLine) { pNewLinePointColl = new PolylineClass(); foreach (List<double> pt in line.geometry.coordinates) { ppoint = new PointClass(); ppoint.X = pt[0]; ppoint.Y = pt[1]; pNewLinePointColl.AddPoint(ppoint); } pFBuffer.Shape = pNewLinePointColl as PolylineClass; pFCurOutLine.InsertFeature(pFBuffer); } pLineLayer.Name = "FusionTableLine"; return pLineLayer; }
public void ExtractPointData(string sLineLayer, string sRasterLayer, double dblInterval,string strFileName) { try { strSaveFile = strFileName; IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IFeatureLayer pLineLayer = FindLayer(sLineLayer) as IFeatureLayer; IRasterLayer pRasterLayer = FindLayer(sRasterLayer) as IRasterLayer; //IFeatureLayer pPointLayer = FindLayer(sPointLayer) as IFeatureLayer; IFeatureLayer pPointLayer = new FeatureLayerClass(); pPointLayer.FeatureClass = MakePointFC(); //pPointLayer.Name = "Points"; // ArcMap.Document.ActiveView.FocusMap.AddLayer(pPointLayer); //get the Workspace from the IDataset interface on the feature class IDataset dataset = (IDataset)pLineLayer.FeatureClass; IWorkspace workspace = dataset.Workspace; //Cast for an IWorkspaceEdit IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; //Start an edit session and operation workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1); pProgressDialog.ShowDialog(); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pPointLayer.Search(null, false); pFCurOutPoints = pPointLayer.FeatureClass.Insert(true); //Set up the LineLayer Cursor IFeatureCursor pFCur = pLineLayer.Search(null, false); IFeature pLineFeature = pFCur.NextFeature(); IFeatureBuffer pFBuffer = pPointLayer.FeatureClass.CreateFeatureBuffer(); ICurve pCurve; double dlbProcessedLength = 0; double dblFCTotalLength = 0; int p = 0; while (pLineFeature != null) { pProgressDialog.Description = "Calculating line segment " + p.ToString() + " of: " + pLineLayer.FeatureClass.FeatureCount(null).ToString(); //create startpoint pCurve = pLineFeature.Shape as ICurve; pFBuffer.Shape = pCurve.FromPoint; pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), 0); pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), pCurve.FromPoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), pCurve.FromPoint.Y); pFCurOutPoints.InsertFeature(pFBuffer); double dblTotalDistance = pCurve.Length; dlbProcessedLength = dblInterval; IConstructPoint contructionPoint; IPoint ppoint; while (dlbProcessedLength <= dblTotalDistance) { contructionPoint = new PointClass(); contructionPoint.ConstructAlong(pCurve, esriSegmentExtension.esriNoExtension, dlbProcessedLength, false); ppoint = new PointClass(); ppoint = contructionPoint as IPoint; pFBuffer.Shape = ppoint; //dblFCTotalLength += dblInterval; pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dlbProcessedLength, 4)); pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID); pFBuffer.set_Value(pFBuffer.Fields.FindField("X"), ppoint.X); pFBuffer.set_Value(pFBuffer.Fields.FindField("Y"), ppoint.Y); pFCurOutPoints.InsertFeature(pFBuffer); dlbProcessedLength += dblInterval; pStepProgressor.Step(); } dblFCTotalLength += dblInterval; p++; pLineFeature = pFCur.NextFeature(); } //cleanup pFCurOutPoints.Flush(); pFCur.Flush(); //Stop editing workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); Extract(pRasterLayer, pPointLayer); pProgressDialog.HideDialog(); pmxdoc.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }
public void Calculate(string sShorelineLayer, string sDepthPointsLayer, double dblInterval, string strShoreDepthField, string strDepthPointDepthField) { try { IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IFeatureLayer pDepthSoundings = FindLayer(pmap, sDepthPointsLayer) as IFeatureLayer; IFeatureLayer pShorelineLayer = FindLayer(pmap, sShorelineLayer) as IFeatureLayer; //IFeatureLayer pOutpoints = FindLayer(pmap, sOutpoints) as IFeatureLayer; IFeatureLayer pOutpoints = new FeatureLayerClass(); pOutpoints.FeatureClass = MakePointFC(); pOutpoints.Name = "Output Points"; ArcMap.Document.ActiveView.FocusMap.AddLayer(pOutpoints); IFeatureLayer pConnectingLines = FindLayer(pmap, "ConnectingLines") as IFeatureLayer; IFeatureLayer pShorePoints = FindLayer(pmap, "ShorePoints") as IFeatureLayer; ////Add fields if necessary //AddField(pOutpoints, "Distance"); //AddField(pOutpoints, "Elevation"); //Set up the Outpoints cursor IFeatureCursor pFCurOutPoints = pOutpoints.Search(null, false); pFCurOutPoints = pOutpoints.FeatureClass.Insert(true); IFeatureBuffer pFOutPointsBuffer = pOutpoints.FeatureClass.CreateFeatureBuffer(); //Set up the LineLayer Cursor (now using selected lines) IFeatureSelection pShoreLineSelection = pShorelineLayer as IFeatureSelection; if (pShoreLineSelection.SelectionSet.Count == 0) { MessageBox.Show("You must have at least one shoreline feature selected"); return; } ICursor pShorelineCursor; IFeatureCursor pSelShoreFeatCur; pShoreLineSelection.SelectionSet.Search(null, false, out pShorelineCursor); pSelShoreFeatCur = pShorelineCursor as IFeatureCursor; IFeature pShoreLineFeature = pSelShoreFeatCur.NextFeature(); //IFeatureCursor pFCur = pShorelineLayer.Search(null, false); //IFeature pShoreLineFeature = pFCur.NextFeature(); //Set up the pConnectingLines cursor IFeatureCursor pFCurOutLines = pConnectingLines.Search(null, false); pFCurOutLines = pConnectingLines.FeatureClass.Insert(true); IFeatureBuffer pFBuffer = pConnectingLines.FeatureClass.CreateFeatureBuffer(); //Set up the pShorePoints cursor IFeatureCursor pShorePointsCursor = pShorePoints.Search(null, false); IFeature pShorePointFeature = pShorePointsCursor.NextFeature(); IFeature pNewLineFeature = null; IPointCollection pNewLinePointColl = null; double dblDistance = 0; double dblTotalDistanceCalculated = 0; int iNumIntervals = 0; double dblElevationDiff = 0; double dblElevationInterval = 0; double dblElevation = 0; double dlbStartElevation = 0; double dblEndElevation = 0; int iLineProgressCount = 0; IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating points for shoreline vertex: ", 0, 1); pProgressDialog.ShowDialog(); IEnvelope pCombinedEnvelope = CombineExtents(pDepthSoundings.FeatureClass, pShorelineLayer.FeatureClass); while (pShoreLineFeature != null) { //IPointCollection4 pPointColl = pShoreLineFeature.Shape as IPointCollection4; IPoint ppoint = new PointClass(); //for (int i = 0; i <= pPointColl.PointCount - 1; i++) while (pShorePointFeature != null) { ppoint = pShorePointFeature.ShapeCopy as IPoint; System.Diagnostics.Debug.WriteLine("ppoint: " + ppoint.X.ToString()); System.Diagnostics.Debug.WriteLine("shorepoint: " + pShorePointFeature.OID.ToString()); ////try walking line at set intervals instead of just at vertices //IPoint pLineVertex = new PointClass(); //pLineVertex = pPointColl.get_Point(i); IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false); IFeatureIndex2 pFtrInd = new FeatureIndexClass(); pFtrInd.FeatureClass = pDepthSoundings.FeatureClass; pFtrInd.FeatureCursor = pDepthCursor; pFtrInd.Index(null, pCombinedEnvelope); IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2; int FtdID = 0; double dDist2Ftr = 0; pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr); IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID); IPoint pEndPoint = new PointClass(); pEndPoint = pCloseFeature.Shape as IPoint; //Make the line here pNewLineFeature = pConnectingLines.FeatureClass.CreateFeature(); pNewLinePointColl = new PolylineClass(); object missing = Type.Missing; pNewLinePointColl.AddPoint(pEndPoint, ref missing, ref missing); pNewLinePointColl.AddPoint(ppoint, ref missing, ref missing); pNewLineFeature.Shape = pNewLinePointColl as PolylineClass; //Check to see if new line crosses land, if not, process it. //bool bLineIntersectsShore = FeatureIntersects(pShorelineLayer, pConnectingLines, pNewLineFeature); bool bLineIntersectsShore = false; if (bLineIntersectsShore == false) { pNewLineFeature.Store(); ICurve pCurve = pNewLineFeature.Shape as ICurve; pCurve.Project(pmap.SpatialReference); //Get the Starting Elevation from the closest depth point dlbStartElevation = GetStartElevation(pDepthSoundings, pConnectingLines, pNewLineFeature, strDepthPointDepthField); //The Elevation for the first run IS the start elevation dblElevation = dlbStartElevation; //////Get the ending elevation from the shoreline dblEndElevation = GetEndElevation(pShorelineLayer, pConnectingLines, pNewLineFeature, strShoreDepthField); //number of line segments based on the user's interval iNumIntervals = Convert.ToInt32(pCurve.Length / dblInterval); dblElevationDiff = Math.Abs(dblEndElevation - dlbStartElevation); //The calculated elevation interval to step up each time dblElevationInterval = dblElevationDiff / iNumIntervals; ppoint = new PointClass(); while (dblTotalDistanceCalculated <= pCurve.Length) { pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("LineOID"), pNewLineFeature.OID); pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("Distance"), dblDistance); pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("Elevation"), dblElevation); //this code set the point on the line at a distance pCurve.QueryPoint(0, dblDistance, false, ppoint); pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("X"), ppoint.X); pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("Y"), ppoint.Y); //reCalc the new distance and elevation values for the next iteration dblDistance = dblDistance + dblInterval; //add or subtract elevation depending on whether dblElevationDiff is positve or negative if (dblElevationDiff > 0) { dblElevation = dblElevation - dblElevationInterval; } else { dblElevation = dblElevation + dblElevationInterval; } dblTotalDistanceCalculated = dblTotalDistanceCalculated + dblInterval; //Insert the feature into the featureclass pFOutPointsBuffer.Shape = ppoint; pFCurOutPoints.InsertFeature(pFOutPointsBuffer); } //Reset the distance values back to 0 for the next feature dblDistance = 0; dblTotalDistanceCalculated = 0; pFCurOutPoints.Flush(); pStepProgressor.Step(); pProgressDialog.Description = "Calculating points for shoreline vertex: " + pShorePointFeature.OID.ToString(); iLineProgressCount++; } pShorePointFeature = pShorePointsCursor.NextFeature(); } pShoreLineFeature = pSelShoreFeatCur.NextFeature(); } //cleanup pFCurOutLines.Flush(); pSelShoreFeatCur.Flush(); pProgressDialog.HideDialog(); pmxdoc.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }