- //returns lists of (("point", color, width, coord)("polyline", color, width, coords)..)
- public List GetFromShpFile(string shpfname, string sourceSystem, string targetSystem, bool StartingProgress) {
- if (StartingProgress) StartProgress("Reading Shapefile...", 2, true);
- //make list of return objects
- List> retItems = new List>();
- try {
- //get epsg codes
- MgCoordinateSystemFactory coordSysFactory = new MgCoordinateSystemFactory();
- string baseSysWkt = coordSysFactory.ConvertCoordinateSystemCodeToWkt(sourceSystem);
- string targetSysWkt = coordSysFactory.ConvertCoordinateSystemCodeToWkt(targetSystem);
- MgCoordinateSystem srcCs = coordSysFactory.Create(baseSysWkt);
- MgCoordinateSystem dstCs = coordSysFactory.Create(targetSysWkt);
- int srccode = srcCs.EpsgCode;
- int tgtcode = dstCs.EpsgCode;
- //now read into dotspacial
- Shapefile sf = Shapefile.OpenFile(shpfname);
- //look at sf.ProjectionString
- if (!File.Exists(Path.GetDirectoryName(shpfname) + "\" + Path.GetFileNameWithoutExtension(shpfname) + ".prj"))
- sf.Projection = ProjectionInfo.FromEpsgCode(srccode);
- sf.Reproject(ProjectionInfo.FromEpsgCode(tgtcode));
- //loop through items
- //will be DotSpatial.Topology.FeatureType. Line, Point, MultiPoint, Polygon, Unspecified
- bool DoClose = false;
- DoClose = DoProgress("Reading linework...", sf.Features.Count);
- int index = 0;
- int done = 0;
- foreach (Feature ft in sf.Features) {
- if (!DoClose) {
- //message every 10 items
- if (done == 9) {
- DoClose = DoProgressBy("Reading linework...", index);
- done = 0;
- }
- DotSpatial.Topology.FeatureType typ = ft.FeatureType;
- string color = "";
- string width = "";
- if (typ == FeatureType.Line || typ == FeatureType.Polygon) {
- //coords
- StringBuilder coords = new StringBuilder("");
- foreach (Coordinate crd in ft.Coordinates) {
- coords.Append(new CE.Point(crd.X, crd.Y, (double.IsNaN(crd.Z) ? 0.0 : crd.Z)).ToXYZString());
- coords.Append(" ");
- }
- if (coords.Length > 0)
- retItems.Add(new List() { "polyline", color, width, coords.ToString() });
- }
- else if (typ == FeatureType.Point) {
- //coords
- StringBuilder coords = new StringBuilder("");
- foreach (Coordinate crd in ft.Coordinates) {
- coords.Append(new CE.Point(crd.X, crd.Y, (double.IsNaN(crd.Z) ? 0.0 : crd.Z)).ToXYZString());
- coords.Append(" ");
- }
- if (coords.Length > 0)
- retItems.Add(new List() { "point", color, width, coords.ToString() });
- }
- else if (typ == FeatureType.MultiPoint) {
- //coords
- StringBuilder coords = new StringBuilder("");
- foreach (Coordinate crd in ft.Coordinates) {
- retItems.Add(new List() { "point", color, width, new CE.Point(crd.X, crd.Y, (double.IsNaN(crd.Z) ? 0.0 : crd.Z)).ToXYZString() });
- }
- }
- else if (typ == FeatureType.Unspecified) {
- }
- }
- index++;
- done++;
- }
- EndProgress(StartingProgress);
- }
- catch { }
- finally {
- CloseProgress(StartingProgress);
- }
- return new List() { retItems };
- }
您可以忽略与进度相关的项目,但Norman Yuan在
http://drive-CAD-with-code . blogspot . ca/2015/04/showing-progress-for-long-code . html
我提到的mapguide引擎就是autodesk在Map3D中使用的。这很疯狂,但他们实际上是免费赠送的,你可以在任何地方使用。你想要的. net程序。
我们在Bricscad和basic acad中使用它进行许多事情,例如制作和导入kmz。
我无法发布我的整个程序。我们公司还没有销售任何软件。