/// <summary> /// 离散Polygon /// </summary> /// <param name="polygon"></param> /// <param name="distance"></param> private IPolygon DiscretePolygon(IPolygon polygon, double distance) { string wkt = "PROJCS[\"<Custom Coordinate>\",GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\",SPHEROID[\"Krasovsky_1940\",6378245.0,298.3]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"false_easting\",64685.26],PARAMETER[\"false_northing\",-3267460.1405],PARAMETER[\"central_meridian\",120.0],PARAMETER[\"scale_factor\",1.0],PARAMETER[\"latitude_of_origin\",0.0],UNIT[\"Meter\",1.0]]"; ICoordinateReferenceSystem tempcrs = crsFactory.CreateFromWKT(wkt); IRing ring = polygon.ExteriorRing; IPolygon resPolygon = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon; resPolygon.SpatialCRS = crs as ISpatialCRS; for (int i = 0; i < ring.PointCount - 1; i++) { IPoint point1 = ring.GetPoint(i); IPoint point2 = ring.GetPoint(i + 1); resPolygon.ExteriorRing.AppendPoint(point1); point1.Project(tempcrs as ISpatialCRS); point2.Project(tempcrs as ISpatialCRS); IVector3 p1 = point1.Position; IVector3 p2 = point2.Position; IEulerAngle angle = this.axRenderControl1.Camera.GetAimingAngles(p1, p2); p2.MultiplyByScalar(-1); double length = p1.Add(p2).Length; for (int j = 0; j < (int)(length / distance); j++) { IVector3 tempv3 = this.axRenderControl1.Camera.GetAimingPoint(p1, angle, (distance * (j + 1))); IPoint tempPoint = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); tempPoint.Position = tempv3; tempPoint.SpatialCRS = tempcrs as ISpatialCRS; tempPoint.Project(crs as ISpatialCRS); resPolygon.ExteriorRing.AppendPoint(tempPoint); } } resPolygon.Close(); return(resPolygon); }
public static Vector3d TestAddThroughOpenGenericInterface <TElement> () { IVector3 <TElement> sum = (IVector3 <TElement>) new Vector3d(); for (int i = 0; i < BufferSize; i++) { sum = sum.Add((IVector3 <TElement>)Vectors[i]); } return((Vector3d)sum); }
/// <summary> /// 参数化建模 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDriveModel_Click(object sender, System.EventArgs e) { try { if (polyline != null) { center = polyline.Envelope.Center; IModelPoint mp = new GeometryFactory().CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint; mp.SpatialCRS = datasetCRS; mp.Position = center; IModel model = new ResourceFactory().CreateModel(); IDrawGroup group = new DrawGroup(); IDrawPrimitive primitive = new DrawPrimitive(); IDrawMaterial material = new DrawMaterial(); material.TextureName = (strMediaPath + @"\shp\road\textrure.jpg"); material.CullMode = gviCullFaceMode.gviCullNone; material.WrapModeS = gviTextureWrapMode.gviTextureWrapRepeat; material.WrapModeT = gviTextureWrapMode.gviTextureWrapRepeat; IFloatArray va = new FloatArray(); IFloatArray ta = new FloatArray(); // 逐点外扩 for (int i = 0; i < polyline.PointCount; i++) { #region 单独处理最后一个点 if (i == polyline.PointCount - 1) { curPoint = polyline.GetPoint(i); vecCurPos = curPoint.Position; // 最后一个点重用最后的方向向量 vecTarget = vecDirect.CrossProduct(vecZ); vecTarget.Normalize(); vecTarget.MultiplyByScalar(width / 2); vecP = vecCurPos.Add(vecTarget); vecTarget.MultiplyByScalar(-1); vecQ = vecCurPos.Add(vecTarget); // 设置外扩点 P = curPoint.Clone() as IPoint; P.Position = vecP; Q = curPoint.Clone() as IPoint; Q.Position = vecQ; // 把点坐标加进顶点数组 va.Append((float)(vecP.X - center.X)); va.Append((float)(vecP.Y - center.Y)); va.Append((float)(vecP.Z - center.Z)); va.Append((float)(vecQ.X - center.X)); va.Append((float)(vecQ.Y - center.Y)); va.Append((float)(vecQ.Z - center.Z)); // 加纹理坐标 ta.Append(0); //P点纹理 if (i == 0) { lastV = 0.0; } else { lastV = lastV + length / 10; //v方向上每隔10米重复一次 } ta.Append((float)lastV); ta.Append(1); //Q点纹理 ta.Append((float)lastV); { ISimplePointSymbol ps = new SimplePointSymbol(); ps.FillColor = System.Drawing.Color.Yellow; ps.Size = 5; rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(P, ps, rootId)); rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(Q, ps, rootId)); } break; } #endregion // 当不是最后一个点时: curPoint = polyline.GetPoint(i); nextPoint = polyline.GetPoint(i + 1); vecCurPos = curPoint.Position; vecNextPos = nextPoint.Position; // 运算 vecNextPos.MultiplyByScalar(-1); vecDirect = vecCurPos.Add(vecNextPos); //方向向量 vecZ.Set(0, 0, 1); vecTarget = vecDirect.CrossProduct(vecZ); vecTarget.Normalize(); vecTarget.MultiplyByScalar(width / 2); vecP = vecCurPos.Add(vecTarget); vecTarget.MultiplyByScalar(-1); vecQ = vecCurPos.Add(vecTarget); // 设置外扩点 P = curPoint.Clone() as IPoint; P.Position = vecP; Q = curPoint.Clone() as IPoint; Q.Position = vecQ; // 把点坐标加进顶点数组 va.Append((float)(vecP.X - center.X)); va.Append((float)(vecP.Y - center.Y)); va.Append((float)(vecP.Z - center.Z)); va.Append((float)(vecQ.X - center.X)); va.Append((float)(vecQ.Y - center.Y)); va.Append((float)(vecQ.Z - center.Z)); // 加纹理坐标 ta.Append(0); //P点纹理 if (i == 0) { lastV = 0.0; } else { lastV = lastV + length / 5; //v方向上每隔10米重复一次 } length = vecDirect.Length; //计算长度给奇数点用 ta.Append((float)lastV); ta.Append(1); //Q点纹理 ta.Append((float)lastV); { ISimplePointSymbol ps = new SimplePointSymbol(); ps.FillColor = System.Drawing.Color.Yellow; ps.Size = 5; rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(P, ps, rootId)); rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(Q, ps, rootId)); } } // 计算索引坐标 IUInt16Array ia = new UInt16Array(); for (int i = 0; i < va.Length / 6 - 1; i++) { ia.Append((ushort)(2 * i)); ia.Append((ushort)(2 * i + 1)); ia.Append((ushort)(2 * i + 2)); ia.Append((ushort)(2 * i + 1)); ia.Append((ushort)(2 * i + 3)); ia.Append((ushort)(2 * i + 2)); } primitive.VertexArray = va; primitive.TexcoordArray = ta; primitive.IndexArray = ia; primitive.Material = material; group.AddPrimitive(primitive); model.AddGroup(group); // 在内存中临时存储模型 string modelName = fid.ToString(); this.axRenderControl1.ObjectManager.AddModel(modelName, model); mp.ModelName = modelName; mp.ModelEnvelope = model.Envelope; // 可视化临时模型 IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId); rmp.MaxVisibleDistance = 100000; rmp.MouseSelectMask = gviViewportMask.gviViewNone; rModelpointToDelList.Add(rmp); } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }