ArcGIS Pro SDK (九)几何 6 包络
文章目录
1 构造包络
MapPoint minPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0);
MapPoint maxPt = MapPointBuilderEx.CreateMapPoint(2.0, 2.0);
Envelope envelope = EnvelopeBuilderEx.CreateEnvelope(minPt, maxPt);
EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(minPt, maxPt);
envelope = builderEx.ToGeometry() as Envelope;
2 构造包络 - 从 JSON 字符串
string jsonString = "{ \"xmin\" : 1, \"ymin\" : 2,\"xmax\":3,\"ymax\":4,\"spatialReference\":{\"wkid\":4326}}";
Envelope envFromJson = EnvelopeBuilderEx.FromJson(jsonString);
3 合并两个包络
Envelope env1 = EnvelopeBuilderEx.CreateEnvelope(0, 0, 1, 1, SpatialReferences.WGS84);
Envelope env2 = EnvelopeBuilderEx.CreateEnvelope(0.5, 0.5, 1.5, 1.5, SpatialReferences.WGS84);
Envelope env3 = env1.Union(env2);
double area = env3.Area;
double depth = env3.Depth;
double height = env3.Height;
double width = env3.Width;
double len = env3.Length;
MapPoint centerPt = env3.Center;
Coordinate2D coord = env3.CenterCoordinate;
bool isEmpty = env3.IsEmpty;
int pointCount = env3.PointCount;
bool isEqual = env1.IsEqual(env2);
EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(0, 0, 1, 1, SpatialReferences.WGS84);
builderEx.Union(env2);
depth = builderEx.Depth;
height = builderEx.Height;
width = builderEx.Width;
centerPt = builderEx.Center;
coord = builderEx.CenterCoordinate;
isEmpty = builderEx.IsEmpty;
env3 = builderEx.ToGeometry() as Envelope;
4 与两个包络相交
Envelope env1 = EnvelopeBuilderEx.CreateEnvelope(0, 0, 1, 1, SpatialReferences.WGS84);
Envelope env2 = EnvelopeBuilderEx.CreateEnvelope(0.5, 0.5, 1.5, 1.5, SpatialReferences.WGS84);
bool intersects = env1.Intersects(env2);
Envelope env3 = env1.Intersection(env2);
EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(0, 0, 1, 1, SpatialReferences.WGS84);
intersects = builderEx.Intersects(env2);
builderEx.Intersection(env2);
env3 = builderEx.ToGeometry() as Envelope;
5 展开包络
Envelope envelope = EnvelopeBuilderEx.CreateEnvelope(100.0, 100.0, 500.0, 500.0);
Envelope result = envelope.Expand(0.5, 0.5, true);
EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(100.0, 100.0, 500.0, 500.0);
builderEx.Expand(0.5, 0.5, true);
envelope = builderEx.ToGeometry() as Envelope;
6 更新包络的坐标
Coordinate2D minCoord = new Coordinate2D(1, 3);
Coordinate2D maxCoord = new Coordinate2D(2, 4);
Coordinate2D c1 = new Coordinate2D(0, 5);
Coordinate2D c2 = new Coordinate2D(1, 3);
EnvelopeBuilderEx builderEx = new EnvelopeBuilderEx(minCoord, maxCoord);
builderEx.XMin = 6;
builderEx.XMax = 8;
builderEx.XMax = 3;
builderEx.YMin = 2;
builderEx.ZMin = 3;
builderEx.ZMax = -1;
builderEx.SetZCoords(8, -5);
builderEx.SetXYCoords(c1, c2);
builderEx.HasM = true;
builderEx.SetMCoords(2, 5);
var geomEx = builderEx.ToGeometry();