ArcGIS Pro SDK 几何
几何
空间参考
构造空间参考 - 从已知 ID
1 | // Use a builder convenience method or use a builder constructor. |
构造空间引用 - 从字符串
1 | // Use a builder convenience method or use a builder constructor. |
使用 WGS84 空间参考
1 | SpatialReference wgs84 = SpatialReferences.WGS84; |
使用垂直坐标系构造空间参考 - 从已知 ID
1 | // Use a builder convenience method or use a builder constructor. |
使用垂直坐标系构造空间参考 - 从字符串
1 | // Use a builder convenience method or use a builder constructor. |
使用自定义 PCS 构造空间参考 - 从字符串
1 | // Use a builder convenience method or use a builder constructor. |
空间参考属性
1 | // Builder constructors need to run on the MCT. |
导入和导出空间参考
1 | SpatialReference srWithVertical = SpatialReferenceBuilder.CreateSpatialReference(4326, 6916); |
确定给定点处空间参考的格网收敛
1 | Coordinate2D coordinate = new Coordinate2D(10, 30); |
基准
1 | var cimMapDefinition = MapView.Active.Map.GetDefinition(); |
空间参照基准和基准属性
1 | // Get datum of a spatial reference |
坐标3D
矢量极坐标
1 | Coordinate3D polarVector = new Coordinate3D(0, 7, 0); |
获取矢量倾角
1 | Coordinate3D v = new Coordinate3D(0, 0, 7); |
获取矢量方位角
1 | Coordinate3D vector = new Coordinate3D(0, 7, 0); |
向量运算
1 | // Easy 3D vectors |
2D 矢量操作
1 | Coordinate2D v = new Coordinate2D(0, 1); |
生成器属性
生成器属性
1 | // list of points |
地图点
构造地图点
1 | // Use a builder convenience method or use a builder constructor. |
地图点生成器属性
1 | // Use a builderEx convenience method or a builderEx constructor. |
地图点是平等的
1 | MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4, 5); |
缩放至指定点
1 | //Create a point |
折线
构造折线 - 从映射点的枚举
1 | // Use a builderEx convenience method or a builderEx constructor. |
获取折线的点
1 | // get the points as a readonly Collection |
获取折线的各个部分
1 | int numParts = polyline.PartCount; |
枚举折线的各个部分
1 | ReadOnlyPartCollection polylineParts = polyline.Parts; |
反转折线中点的顺序
1 | var polylineBuilder = new PolylineBuilderEx(polyline); |
获取折线的段
1 | ICollection<Segment> collection = new List<Segment>(); |
构建多部分折线
1 | List<MapPoint> firstPoints = new List<MapPoint>(); |
折线的起点
1 | // Method 1: Get the start point of the polyline by converting the polyline |
按角度构造布料
1 | MapPoint startPoint = MapPointBuilderEx.CreateMapPoint(0, 0); |
按长度构造布料
1 | MapPoint startPoint = MapPointBuilderEx.CreateMapPoint(0, 0); |
远距离分割折线
1 | // create list of points |
多边形
构造多边形 - 从映射点的枚举
1 | // Use a builderEx convenience method or use a builderEx constructor. |
构造多边形 - 从信封
1 | // Use a builderEx convenience method or use a builderEx constructor. |
获取多边形的点
1 | // get the points as a readonly Collection |
获取多边形的各个部分
1 | // get the parts as a readonly collection |
枚举多边形的各个部分
1 | int numSegments = 0; |
获取多边形的线段
1 | List<Segment> segmentList = new List<Segment>(30); |
构建圆环多边形
1 | List<Coordinate2D> outerCoordinates = new List<Coordinate2D>(); |
创建 N 侧正多边形
1 | // <summary> |
获取多边形的外环 - 多边形。获取外部环
1 | public void GetExteriorRings(Polygon inputPolygon) |
信封
构造封套
1 | // Use a builderEx convenience method or use a builderEx constructor. |
构造信封 - 从 JSON 字符串
1 | string jsonString = "{ \"xmin\" : 1, \"ymin\" : 2,\"xmax\":3,\"ymax\":4,\"spatialReference\":{\"wkid\":4326}}"; |
合并两个信封
1 | // use the convenience builders |
与两个信封相交
1 | // use the convenience builders |
展开信封
1 | // Use a builderEx convenience method or use a builderEx constructor. |
更新封套的坐标
1 | Coordinate2D minCoord = new Coordinate2D(1, 3); |
多点
构造多点 - 从映射点的枚举
1 | // Use a builderEx convenience method or use a builderEx constructor. |
构造多点 - 使用 MultipointBuilderEx
1 | Coordinate2D[] coordinate2Ds = new Coordinate2D[] { new Coordinate2D(1, 2), new Coordinate2D(-1, -2) }; |
修改多点的点
1 | // assume a multiPoint has been built from 4 points |
从多点检索点、2D 坐标、3D 坐标
1 | ReadOnlyPointCollection points = multipoint.Points; |
线段
使用两个地图点构造线段
1 | // Use a builderEx convenience method or use a builderEx constructor. |
更改线段坐标
1 | // builderEx constructors don't need to run on the MCT |
立方贝塞尔
构建三次方贝塞尔 - 从坐标
1 | // Use a builderEx convenience method or a builderEx constructor. |
构建立方贝塞尔 - 从地图点
1 | // Use a builderEx convenience method or a builderEx constructor. |
构造三次贝塞尔 - 从映射点的枚举
1 | // Use a buildeExr convenience method or use a builderEx constructor. |
立方贝塞尔生成器属性
1 | // retrieve the bezier curve's control points |
立方贝塞尔属性
1 | // retrieve the bezier curve's control points |
构造折线 - 从三次贝塞尔
1 | Polyline polyline = PolylineBuilderEx.CreatePolyline(bezierSegment); |
弧
构造圆弧 - 使用内部点
1 | // Construct a circular arc from (2, 1) to (1, 2) with interior pt (1 + sqrt(2)/2, 1 + sqrt(2)/2). |
构造圆弧 - 使用弦长度和方位
1 | // Construct a circular arc counterclockwise from (2, 1) to (1, 2) such that the embedded |
构建圆弧 - 使用中心点、角度和半径
1 | // Construct a circular arc with center point at (0, 0), from angle = 0, |
构造椭圆弧 - 使用中心点和旋转角度
1 | // Construct an elliptic arc centered at (1,1), startAngle = 0, centralAngle = PI/2, |
构造圆弧 - 使用中心点和方向
1 | // Construct a circular arc from (2, 1) to (1, 2) |
构造圆弧 - 使用两个线段和半径
1 | // Construct a segment from (100, 100) to (50, 50) and another segment from (100, 100) to (150, 50). |
构造一个圆
1 | // Construct a circle with center at (-1,-1), radius = 2, and oriented clockwise. |
构造椭圆
1 | // Construct an ellipse centered at (1, 2) with rotationAngle = -pi/6, |
Elliptic Arc Builder Properties
1 | // retrieve the curve's properties |
椭圆弧属性
1 | // retrieve the curve's control points |
几何袋
构造几何包
1 | MapPoint point = MapPointBuilderEx.CreateMapPoint(1, 2, SpatialReferences.WebMercator); |
构造几何包 - 从几何枚举
1 | // Use a builder convenience method or use a builder constructor. |
ConstructingGeometryBag - 来自 JSON、Xml
1 | const string jsonString = "{\"geometries\":[{\"x\":1,\"y\":2},{\"rings\":[[[0,0],[0,4],[3,4],[3,0],[0,0]]]}],\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}"; |
构造几何包 - 添加或插入几何枚举
1 | MapPoint point = MapPointBuilderEx.CreateMapPoint(10, 20); |
多面体
通过拉伸多边形或折线构建多面体
1 | // build a polygon |
多面体属性
1 | // standard geometry properties |
构建多面体
1 | // export to binary xml |
通过MultipatchBuilderEx构建多面体
1 | var coords_face1 = new List<Coordinate3D>() |
从另一个多面体构建多面体
1 | // create the multipatchBuilderEx object |
从 3D 模型文件构建多面体
1 | try |
构建 3D 特殊多面体形状
1 | var sr = MapView.Active.Map.SpatialReference; |
创建基本材料
1 | // Create BasicMaterial with default values |
使用 JPEG 纹理创建基本材质
1 | // read the jpeg into a buffer |
使用未压缩纹理创建基本材质
1 | UncompressedTexture uncompressedTexture1 = new UncompressedTexture(new byte[10 * 12 * 3], 10, 12, 3); |
获取多面体的纹理图像
1 | // <summary> |
获取多面体的法线坐标
1 | // <summary> |
获取多面体的法线
1 | // <summary> |
获取多面体的材质属性
1 | public void GetMaterialProperties(Multipatch multipatch, int patchIndex) |
多部件
获取多部分要素的各个部分
1 | public IEnumerable<Geometry> MultipartToSinglePart(Geometry inputGeometry) |
获取多边形的最外层环
1 | public Polygon GetOutermostRings(Polygon inputPolygon) |
从地理数据库检索几何
从地理数据库检索几何
1 | // methods need to run on the MCT |
导入、导出几何图形
将几何图形导入和导出为已知文本
1 | // create a point with z, m |
将几何图形导入和导出到众所周知的二进制
1 | // create a polyline |
将几何导入和导出到 EsriShape
1 | // create an envelope |
将几何图形导入和导出为 JSON
1 | // MapPoint |
将几何图形导入和导出为 XML
1 | MapPoint minPoint = MapPointBuilderEx.CreateMapPoint(1, 1, 1, 1, 3); |
转换
创建地理转换
1 | // create from wkid |
创建复合地理变换
1 | // Create singleton from wkid |
创建投影转换
1 | // methods need to be on the MCT |
创建高压基准变换
1 | // Create from wkid |
创建复合高压基准变换
1 | HVDatumTransformation hv1 = HVDatumTransformation.Create(108034); |
确定转换
1 | // methods need to run on the MCT |
地图点地理坐标字符串
地图点 - 地理坐标字符串转换
1 | SpatialReference sr = SpatialReferences.WGS84; |
角度单元
角度单位 - 在度和弧度之间转换
1 | // convert 45 degrees to radians |
角度单位 - 使用工厂代码创建角度单位
1 | try |
角度单位 - 创建自定义角度单位
1 | // custom unit - 3 radians per unit |
线性单位
线性单位 - 在英尺和米之间转换
1 | // convert 10 feet to meters |
线性单位 - 在厘米和毫米之间转换
1 | // convert 11 centimeters to millimeters |
线性单位 - 使用工厂代码创建线性单位
1 | try |
线性单位 - 创建自定义线性单位
1 | // create a custom linear unit - there are 0.33 meters per myLinearUnit |
面积单位
面积单位 - 在平方英尺和平方米之间转换
1 | // convert 700 square meters to square feet |
面积单位 - 在公顷和英亩之间转换
1 | // convert 2 hectares to acres |
面积单位 - 在公顷和平方英里之间转换
1 | // convert 300 hectares to square miles |
面积单位 - 各种单位的平方米数
1 | double sqMetersPerUnit = AreaUnit.Acres.SquareMetersPerUnit; |
面积单位 - 创建面积单位
1 | try |
几何引擎函数
加速几何图形
1 | // Use acceleration to speed up relational operations. Accelerate your source geometry only if you are going to test many other geometries against it. |
确定面的面积
1 | var g1 = PolygonBuilderEx.FromJson("{\"rings\": [ [ [0, 0], [10, 0], [10, 10], [0, 10] ] ] }"); |
确定多部分多边形的边界
1 | // create a donut polygon. Must use the PolygonBuilderEx object |
缓冲地图点
1 | // buffer a point |
缓冲圆弧
1 | // create the circular arc |
缓冲多个地图点
1 | // creates a buffer around each MapPoint |
缓冲多种不同的几何类型
1 | List<Coordinate2D> coords = new List<Coordinate2D>() |
在折线上插值 Z 值
1 | List<Coordinate3D> coords2 = new List<Coordinate3D>() |
在多边形上插值 M 值
1 | List<MapPoint> coords = new List<MapPoint>() |
将封套在 X,Y 周围居中
1 | Envelope env = EnvelopeBuilderEx.CreateEnvelope(1.0, 1.0, 5.0, 5.0); |
查找几何体的质心
1 | // simple polygon |
剪裁折线
1 | // clip a polyline by an envelope |
按多边形裁剪折线
1 | // clip a polyline by a polygon |
构建具有指定距离和方位角的大地测量线
1 | var sr = SpatialReferenceBuilder.CreateSpatialReference(4326); |
构建连接点的大地测量线
1 | var sr = SpatialReferenceBuilder.CreateSpatialReference(4326); |
在距现有点一定距离和一定角度处构造点
1 | MapPoint inPoint = MapPointBuilderEx.CreateMapPoint(3, 4); |
从一组折线构造多边形
1 | List<Coordinate2D> firstLinePts = new List<Coordinate2D>(); |
多边形包含地图点、折线、多边形
1 | // build a polygon |
确定凸包
1 | // |
确定两个几何图形是否相交
1 | // |
使用折线切割几何图形
1 | SpatialReference sr = SpatialReferences.WGS84; |
按长度致密
1 | // densify a line segment |
两个多边形之间的差异
1 | List<MapPoint> polyPts = new List<MapPoint>(); |
确定两个几何是否不相交
1 | // |
确定两个几何之间的距离
1 | MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1.0, 1.0); |
确定两个几何体之间的 3D 距离
1 | // between points |
展开信封
1 | Envelope env = EnvelopeBuilderEx.CreateEnvelope(100.0, 100.0, 500.0, 500.0); |
扩展折线
1 | // build a polyline |
概括
1 | Polyline generalizedPolyline = GeometryEngine.Instance.Generalize(polylineWithZ, 200) as Polyline; |
计算面的测地线面积
1 | var polygon = PolygonBuilderEx.CreatePolygon(new[] |
在指定的测地线距离处创建缓冲区面
1 | // buffer a point |
确定两个几何之间的测地线距离
1 | var point1 = MapPointBuilderEx.CreateMapPoint(-170, 45, SpatialReferences.WGS84); |
测地线椭圆
1 | GeodesicEllipseParameter param = new GeodesicEllipseParameter(); |
确定线的测地线长度
1 | var polyline = PolylineBuilderEx.CreatePolyline(new[] |
测地线扇区
1 | GeodesicSectorParameter param = new GeodesicSectorParameter(); |
大地测量致密化偏差 - 折线
1 | List<Coordinate2D> coords = new List<Coordinate2D>() |
大地测量致密按长度 - 多边形
1 | List<Coordinate2D> coords = new List<Coordinate2D>() |
计算大地测量距离,两点之间的方位角
1 | SpatialReference sr = SpatialReferences.WGS84; |
对一组地图点执行大地测量移动
1 | SpatialReference sr = SpatialReferences.WebMercator; |
检索坐标系
1 | // get all the geographic coordinate systems |
检索系统地理变换
1 | // a geographic transformation is the definition of how to project from one spatial reference to another |
获取折线或多边形的子曲线
1 | SpatialReference sr = SpatialReferences.WGS84; |
图形缓冲区
1 | // mitered join and butt caps |
图形缓冲器很多
1 | // round join and round caps |
两条折线之间的交点
1 | // determine intersection between two polylines |
两个多边形之间的交点
1 | // determine intersection between two polygons |
确定多边形的标注点
1 | // create a polygon |
确定线的长度,长度3D
1 | MapPoint c1 = MapPointBuilderEx.CreateMapPoint(1, 2, 3); |
获取最小和最大 M 值 - GetMinMaxM
1 | string json = "{\"hasM\":true,\"rings\":[[[-3000,-2000,10],[-2000,-2000,15],[-1000,-2000,20],[0,-2000,0],[1000,-2000,-20],[2000,-2000,-30],[3000,-2000,10],[4000,-2000,5]]],\"spatialReference\":{\"wkid\":3857}}"; |
确定 M 是单调的,是升序还是降序 - GetMMonotonic
1 | string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,15],[-1000,-2000,20]]]}"; |
获取与几何图形中指定 M 值出现的位置相对应的多点 - GetPointsAtM
1 | string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,15],[-1000,-2000,20],[0,-2000,0],[1000,-2000,20],[2000,-2000,30],[3000,-2000,10],[4000,-2000,5]]],\"spatialReference\":{\"wkid\":3857}}"; |
获取与指定 M 值之间的子曲线对应的折线 - GetSubCurveBetweenMs
1 | string json = "{\"hasM\":true,\"paths\":[[[-2000,0,1],[-1000,1000,2],[-1000,0,3],[1000,1000,4],[2000,1000,5],[2000,2000,6],[3000,2000,7],[4000,0,8]]],\"spatialReference\":{\"wkid\":3857}}"; |
获取与沿几何图形中出现指定 M 值的位置处的法线对应的线段 - GetNormalsAtM
1 | IList<MapPoint> inPoints = new List<MapPoint>() |
获取沿多部分的指定距离处的 M 值
1 | string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2]],[[-2000,-2000,1],[-2000,1000,2]]],\"spatialReference\":{\"wkid\":3857}}"; |
将 M 值设置为从多部分开始的累积长度 - SetMsAsDistance
1 | string json = "{\"hasM\":true,\"rings\":[[[0,0],[0,3000],[4000,3000],[4000,0],[0,0]]],\"spatialReference\":{\"wkid\":3857}}"; |
在给定距离处插入 M 值 - 插入距离
1 | string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,null]]]}"; |
使用输入点的 M 值校准 M 值 - CalibrateByMs
1 | string json = "{\"hasM\":true,\"paths\":[[[0,0,-1],[1,0,0],[1,1,1],[1,2,2],[3,1,3],[5,3,4],[9,5,5],[7,6,6]]],\"spatialReference\":{\"wkid\":4326}}"; |
通过对一系列点进行线性插值生成 M 值 - 插值MsBetween
1 | string json = "{\"hasM\":true,\"paths\":[[[0,0,-1],[1,0,0],[1,1,1],[1,2,2],[3,1,3],[5,3,4],[9,5,5],[7,6,6]]],\"spatialReference\":{\"wkid\":4326}}"; |
在几何图形的开头和结尾设置 Ms,并在两个值之间插值 M 值 - SetAndIntervalateMsBetween
1 | string json = "{\"hasM\":true,\"paths\":[[[-3000,-2000],[-2000,-2000],[-1000,-2000],[0,-2000],[1000,-2000],[2000,-2000],[3000,-2000],[4000,-2000]]],\"spatialReference\":{\"wkid\":3857}}"; |
移动地图点
1 | MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 3.0); |
移动 z 感知地图点
1 | MapPoint zPt = MapPointBuilderEx.CreateMapPoint(1.0, 3.0, 2.0); |
移动折线
1 | List<MapPoint> pts = new List<MapPoint>(); |
移动点沿线
1 | LineSegment line = LineBuilderEx.CreateLineSegment(MapPointBuilderEx.CreateMapPoint(0, 3), MapPointBuilderEx.CreateMapPoint(5.0, 3.0)); |
将几何体的组件分离为单个组件几何图形
1 | List<Coordinate2D> coords2D = new List<Coordinate2D>() |
最近点与最近顶点
1 | SpatialReference sr = SpatialReferences.WGS84; |
确定 3D 中的最近点
1 | MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1, 1, 1); |
计算与源的几何偏移
1 | List<MapPoint> linePts = new List<MapPoint>(); |
确定几何图形是否重叠
1 | MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1.5, 1.5); |
从 WGS84 到 Web墨卡托的项目
1 | MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 3.0, SpatialReferences.WGS84); |
WGS84的项目
1 | // create the polygon |
查询正常
1 | string json = "{\"curvePaths\":[[[-13046586.8335,4036570.6796000004]," + |
查询点
1 | SpatialReference sr = SpatialReferences.WGS84; |
查询点和距离
1 | // Horizontal line segment |
查询切线
1 | LineSegment line = LineBuilderEx.CreateLineSegment(new Coordinate2D(0, 0), new Coordinate2D(1, 0)); |
围绕线反射多边形
1 | SpatialReference sr = SpatialReferences.WGS84; |
确定两个几何图形之间的关系
1 | // set up some geometries |
替换多边形中的 NaN Z
1 | List<Coordinate3D> coordsZ = new List<Coordinate3D>() |
改变多边形的形状
1 | List<Coordinate2D> polygon1Coords = new List<Coordinate2D>() |
反转多边形中点的顺序
1 | List<Coordinate2D> list2D = new List<Coordinate2D>(); |
旋转地图点
1 | MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 3.0); |
旋转折线
1 | // rotate a polyline |
缩放几何图形
1 | List<MapPoint> pts = new List<MapPoint>(); |
设置折线中的所有 Z
1 | List<Coordinate3D> coordsZ = new List<Coordinate3D>() |
计算地球椭球体表面上的几何面积 - 形状保存面积
1 | // pt |
计算地球椭球体表面几何形状的长度 - 形状保存长度
1 | // pt |
侧缓冲器
1 | // right side, round caps |
侧缓冲器很多
1 | SpatialReference spatialReference = SpatialReferenceBuilder.CreateSpatialReference(102010); |
简化多边形
1 | var g1 = PolygonBuilderEx.FromJson("{\"rings\": [ [ [0, 0], [10, 0], [10, 10], [0, 10] ] ] }"); |
简化具有相交、重叠的折线
1 | List<Coordinate2D> coords = new List<Coordinate2D>() |
将多边形切成相等的部分
1 | var slices = GeometryEngine.Instance.SlicePolygonIntoEqualParts(polygon, 3, 0, SliceType.Blocks); |
在点拆分多部分
1 | // define a polyline |
多边形接触另一个多边形
1 | // two disjoint polygons |
转换2D
1 | // Not all of the input points are transformed as some of them are outside of the GCS horizon. |
转换3D
1 | // Not all of the input points are transformed as some of them are outside of the GCS horizon. |
合并两个地图点 - 创建一个多点
1 | MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1.0, 1.0); |
并集两个多边形
1 | // union two polygons |
联合许多折线
1 | // union many polylines |
联合多个多边形
1 | // union many polygons |
地图点、折线、多边形内的多边形
1 | // build a polygon |
e
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 WineMonk!
评论