private static void AddSeriesToFeatureSet(Series series, IFeatureSet fs) { double lat = series.Site.Latitude; double lon = series.Site.Longitude; var pt = new Point(lon, lat); var newFeature = fs.AddFeature(pt); var featureRow = newFeature.DataRow; featureRow["DataSource"] = series.Source.Organization; featureRow["SeriesID"] = series.Id; featureRow["SiteName"] = series.Site.Name; featureRow["Latitude"] = series.Site.Latitude; featureRow["Longitude"] = series.Site.Longitude; featureRow["SiteCode"] = series.Site.Code; featureRow["VarName"] = series.Variable.Name; featureRow["DataType"] = series.Variable.DataType; featureRow["SampleMed"] = series.Variable.SampleMedium; featureRow["VarCode"] = series.Variable.Code; featureRow["Units"] = series.Variable.VariableUnit.Name; featureRow["Method"] = series.Method.Description; featureRow["QCLevel"] = series.QualityControlLevel.Definition; featureRow["StartDate"] = ConvertTime(series.BeginDateTime); featureRow["EndDate"] = ConvertTime(series.EndDateTime); featureRow["ValueCount"] = series.ValueCount; featureRow["ServiceCode"] = series.Variable.Code; }
public static void PopulateFeatureSet(IEnumerable <JoobGeometry> geometries, IFeatureSet featureSet) { if (geometries != null && geometries.Count() > 0) { var reader = new WkbReader(); var minX = double.PositiveInfinity; var minY = double.PositiveInfinity; var maxX = double.NegativeInfinity; var maxY = double.NegativeInfinity; foreach (var geom in geometries.Where(g => g != null)) { var feature = reader.Read(geom.GeoData); var envelope = feature.Envelope; if (envelope != null) { if (envelope.Minimum.X < minX) { minX = envelope.Minimum.X; } if (envelope.Minimum.Y < minY) { minY = envelope.Minimum.Y; } if (envelope.Maximum.X > maxX) { maxX = envelope.Maximum.X; } if (envelope.Maximum.Y > maxY) { maxY = envelope.Maximum.Y; } } featureSet.AddFeature(feature); } if (!double.IsInfinity(minX)) { featureSet.Extent.MinX = minX; } if (!double.IsInfinity(minY)) { featureSet.Extent.MinY = minY; } if (!double.IsInfinity(maxX)) { featureSet.Extent.MaxX = maxX; } if (!double.IsInfinity(maxY)) { featureSet.Extent.MaxY = maxY; } } }
/// <summary> /// 含圆形的要素处理不了 /// </summary> /// <param name="pDT"></param> /// <param name="shpFile"></param> /// <param name="RowIdx"></param> /// <param name="endRowIdx"></param> /// <returns></returns> private void Table2ShapeFile(IFeatureSet feaSet, DataTable pDT, string ShapeColumnName) { //给要素集添加属性 List <string> attriNames = new List <string>(); foreach (DataColumn dataCol in pDT.Columns) { if (dataCol.ColumnName != ShapeColumnName) { attriNames.Add(dataCol.ColumnName); feaSet.DataTable.Columns.Add(dataCol.ColumnName, dataCol.DataType); } } //给要素集添加要素 IGeometry pGeo = null; IFeature pFea = null; DataRow dr = null; for (int i = 0; i < pDT.Rows.Count; i++) { dr = pDT.Rows[i]; switch (feaSet.FeatureType) { case FeatureType.Point: pGeo = CreatePointFromDataRow(dr, ShapeColumnName); break; case FeatureType.MultiPoint: pGeo = CreateMultiPointFromDataRow(dr, ShapeColumnName); //需要补充 break; case FeatureType.Line: pGeo = CreateLineStrFromDataRow(dr, ShapeColumnName); break; case FeatureType.Polygon: pGeo = CreatePolygonFromDataRow(dr, ShapeColumnName); break; } //处理属性 pFea = feaSet.AddFeature(pGeo); foreach (string colName in attriNames) { pFea.DataRow[colName] = dr[colName]; } } }
private void btnStart_Click(object sender, RoutedEventArgs e) { if (this.m_CurrentFeaset == null) { MessageBox.Show("Please select a target layer"); return; } if (this.txtPath.Text == "") { MessageBox.Show("Please select save path"); return; } this.groupAdd.IsEnabled = false; this.btnEnd.IsEnabled = true; //start MainWindow.m_DotMap.Cursor = System.Windows.Forms.Cursors.Cross; //创建新的FeatureSet 复制要素 m_ResultFeaset = new FeatureSet(FeatureType.Point); foreach (DataColumn column in m_CurrentFeaset.DataTable.Columns) { DataColumn col = new DataColumn(column.ColumnName, column.DataType); m_ResultFeaset.DataTable.Columns.Add(col); } foreach (var fea in m_CurrentFeaset.Features) { IFeature pFea = m_ResultFeaset.AddFeature(fea.Geometry); for (int i = 0; i < fea.DataRow.ItemArray.Count(); i++) { pFea.DataRow[i] = fea.DataRow[i]; } } m_ResultFeaset.Projection = MainWindow.m_DotMap.Projection; m_ResultFeaset.Name = m_CurrentFeaset.Name; m_PointLayer = MainWindow.m_DotMap.Layers.Add(m_ResultFeaset); m_PointLayer.LegendText = m_ResultFeaset.Name + "_copy"; }
/// <summary> /// This function gets the site information. /// </summary> private Site getSitesParameters(PolygonData polygon) { IFeature centroid = polygon.polygon.Centroid(); var newpoint = sitesPoints.AddFeature(centroid); Site site = new Site(); var xy = new[] { centroid.Coordinates.First().X, centroid.Coordinates.First().Y }; String projectionString = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[" + "\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; var _wgs84Projection = ProjectionInfo.FromEsriString(projectionString); Reproject.ReprojectPoints(xy, new double[] { 0, 0 }, App.Map.Projection, _wgs84Projection, 0, 1); int indexNumber = (polygonData.IndexOf(polygon) + 1); site.Code = "CrwrAggregation:" + OutputResultName.Text + indexNumber.ToString(); newpoint.DataRow.BeginEdit(); newpoint.DataRow["SiteCode"] = site.Code.ToString(); newpoint.DataRow.EndEdit(); site.Name = OutputResultName.Text + indexNumber.ToString(); site.Latitude = xy[1]; site.Longitude = xy[0]; //site.Elevation_m = 12; site.VerticalDatum = "Unkown"; //site.LocalX = 12; //site.LocalY = 12; //site.PosAccuracy_m = 12; site.State = ""; site.County = ""; //site.Comments = "testing"; //site.Country = "Mexico"; //site.SiteType = "Type"; return(site); }
/// <summary> /// Create polygons from raster. /// </summary> /// <param name="input">The Polygon Raster(Grid file).</param> /// <param name="connectionGrid">Connection Grid.</param> /// <param name="output">The Polygon shapefile path.</param> /// <param name="cancelProgressHandler">The progress handler.</param> public bool Execute(IRaster input, IRaster connectionGrid, IFeatureSet output, ICancelProgressHandler cancelProgressHandler) { if (input == null || output == null) { return false; } output.DataTable.Columns.Add("Value", typeof(double)); var featureHash = new Dictionary<double, LineSegmentList>(); var previous = 0.0; var height = input.CellHeight; var width = input.CellWidth; var xMin = input.Xllcenter - width / 2.0; var yMin = input.Yllcenter - height / 2.0; var xMax = xMin + width * input.NumColumns; var yMax = yMin + height * input.NumRows; var numRows = input.NumRows; var numColumns = input.NumColumns; Func<int, int, double, bool> same = (y, x, value) => y >= 0 && y < numRows && x >= 0 && x < numColumns && input.Value[y, x] == value; Func<int, int, double> get = (y, x) => y >= 0 && y < numRows && x >= 0 && x < numColumns ? input.Value[y, x] : input.NoDataValue; Func<int, int, int, int, bool> eqValues = (y1, x1, y2, x2) => get(y1, x1) == get(y2, x2); var enableCon = connectionGrid != null; Func<int, int, int> connection = (y, x) => enableCon ? (int) connectionGrid.Value[y, x] : 0; for (int y = 0; y < numRows; y++) { int current = Convert.ToInt32((y * 100.0) / input.NumRows); if (current > previous) { cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted); previous = current; } Debug.WriteLine("Row : " + y + " done."); for (int x = 0; x < numColumns; x++) { var value = input.Value[y, x]; if (value == input.NoDataValue) { continue; } LineSegmentList lineList; if (!featureHash.TryGetValue(value, out lineList)) { lineList = new LineSegmentList(); featureHash.Add(value, lineList); } var curCon = connection(y, x); /* 6 7 8 5 0 1 4 3 2 current cell (x,y)=0 */ var con_7 = same(y + 1, x, value); var con_5 = same(y, x - 1, value); var con_3 = same(y - 1, x, value); var con_1 = same(y, x + 1, value); var con_8l = enableCon && same(y + 1, x + 1, value) && !con_7 && (curCon == 8 || connection(y + 1, x + 1) == 4); var con_8r = enableCon && same(y + 1, x + 1, value) && !con_1 && (curCon == 8 || connection(y + 1, x + 1) == 4); var con_6l = enableCon && same(y + 1, x - 1, value) && !con_5 && (curCon == 6 || connection(y + 1, x - 1) == 2); var con_6r = enableCon && same(y + 1, x - 1, value) && !con_7 && (curCon == 6 || connection(y + 1, x - 1) == 2); var con_4l = enableCon && same(y - 1, x - 1, value) && !con_5 && (curCon == 4 || connection(y - 1, x - 1) == 8); var con_4r = enableCon && same(y - 1, x - 1, value) && !con_3 && (curCon == 4 || connection(y - 1, x - 1) == 8); var con_2l = enableCon && same(y - 1, x + 1, value) && !con_3 && (curCon == 2 || connection(y - 1, x + 1) == 6); var con_2r = enableCon && same(y - 1, x + 1, value) && !con_1 && (curCon == 2 || connection(y - 1, x + 1) == 6); /* Cell points: tl tc tr cl cr bl bc br */ var tl = new Coordinate(xMin + x*width, yMax - (y + 1)*height); var tc = new Coordinate(xMin + (x + 0.5)*width, yMax - (y + 1)*height); var tr = new Coordinate(xMin + (x + 1)*width, yMax - (y + 1)*height); var cl = new Coordinate(xMin + x*width, yMax - (y + 0.5)*height); var cr = new Coordinate(xMin + (x + 1)*width, yMax - (y + 0.5)*height); var bl = new Coordinate(xMin + x * width, yMax - y * height); var bc = new Coordinate(xMin + (x + 0.5)*width, yMax - y*height); var br = new Coordinate(xMin + (x + 1)*width, yMax - y*height); /* Cell edges: e_tl e_tr ----|---- e_lt | | e_rt - - e_lb | | e_rb ----|---- e_bl e_br */ bool e_tr = false, e_tl = false, e_lt = false, e_lb = false, e_rt = false, e_rb = false, e_br = false, e_bl = false; if (!con_7) { #region Check Cell 7 // top: right half if (!con_8l) { var a1 = con_6r && con_1; var a2 = !con_8r && !con_6l && con_4l && !con_2r; e_tr = a1 || a2; } // top: left half if (!con_6r) { var a1 = con_8l && con_5; var a2 = !con_8r && !con_6l && !con_4l && con_2r; e_tl = a1 || a2; } // top: full if (!con_8l && !con_6r && !con_4l && !con_2r) { e_tr = e_tl = true; } #endregion } if (!con_3) { #region Check Cell 3 // bottom: left half if (!con_4r) { var a1 = con_2l && con_5; var a2 = !con_2r && !con_4l && !con_6l && con_8r; e_bl = a1 || a2; } // bottom: right half if (!con_2l) { var a1 = con_4r && con_1; var a2 = !con_2r && !con_4l && !con_8r && con_6l; e_br = a1 || a2; } // bottom: full if (!con_4r && !con_2l && !con_8r && !con_6l) { e_bl = e_br = true; } #endregion } if (!con_1) { #region Check Cell 1 // right: bottom half if (!con_2r) { var a1 = con_8r && con_3; var a2 = !con_2l && !con_8l && !con_4r && con_6r; e_rb = a1 || a2; } // right: top half if (!con_8r) { var a1 = con_2r && con_7; var a2 = !con_2l && !con_8l && !con_6r && con_4r; e_rt = a1 || a2; } // right: full if (!con_2r && !con_8r && !con_4r && !con_6r) { e_rb = e_rt = true; } #endregion } if (!con_5) { #region Check Cell 5 // left: bottom half if (!con_4l) { var a1 = con_3 && con_6l; var a2 = !con_6r && !con_4r && con_8l && !con_2l; e_lb = a1 || a2; } // left: top half if (!con_6l) { var a1 = con_4l && con_7; var a2 = !con_6r && !con_4r && !con_8l && con_2l; e_lt = a1 || a2; } // left: full if (!con_4l && !con_6l && !con_8l && !con_2l) { e_lb = e_lt = true; } #endregion } // Smooth boundaries regarding to outer cells // Right top corner if (e_tr && e_rt) { if (eqValues(y + 1, x, y, x + 1)) { var a1 = connection(y + 1, x); var a2 = connection(y, x + 1); if ((a1 == 6 || a1 == 2 || a2 == 6 || a2 == 2) && !(a1 == 6 && a2 == 2)) { lineList.AddSegment(tc, cr); e_tr = e_rt = false; } } } // Left top corner if (e_tl && e_lt) { if (eqValues(y, x - 1, y + 1, x)) { var a1 = connection(y, x - 1); var a2 = connection(y + 1, x); if ((a1 == 8 || a1 == 4 || a2 == 8 || a2 == 4) && !(a1 == 8 && a2 == 4)) { lineList.AddSegment(tc, cl); e_tl = e_lt = false; } } } // Left bottom corner if (e_bl && e_lb) { if (eqValues(y - 1, x, y, x - 1)) { var a1 = connection(y - 1, x); var a2 = connection(y, x - 1); if ((a1 == 6 || a1 == 2 || a2 == 6 || a2 == 2) && !(a1 == 6 && a2 == 2)) { lineList.AddSegment(cl, bc); e_bl = e_lb = false; } } } // Right bottom corner if (e_br && e_rb) { if (eqValues(y, x + 1, y - 1, x)) { var a1 = connection(y, x + 1); var a2 = connection(y - 1, x); if ((a1 == 8 || a1 == 4 || a2 == 8 || a2 == 4) && !(a1 == 8 && a2 == 4)) { lineList.AddSegment(bc, cr); e_br = e_rb = false; } } } // Smooth boundaries regarding direction of current cell switch (curCon) { case 2: case 6: if (e_tr && e_rt) { lineList.AddSegment(tc, cr); e_tr = e_rt = false; } if (e_bl && e_lb) { lineList.AddSegment(bc, cl); e_bl = e_lb = false; } break; case 4: case 8: if (e_tl && e_lt) { lineList.AddSegment(cl, tc); e_tl = e_lt = false; } if (e_br && e_rb) { lineList.AddSegment(cr, bc); e_br = e_rb = false; } break; } // Add remaining edges // Top if (e_tl && e_tr) { lineList.AddSegment(tl, tr); } else if (e_tl) { lineList.AddSegment(tl, tc); } else if(e_tr) { lineList.AddSegment(tc, tr); } //Left if (e_lt && e_lb) { lineList.AddSegment(tl, bl); } else if (e_lt) { lineList.AddSegment(tl, cl); } else if (e_lb) { lineList.AddSegment(cl, bl); } // Bottom if (e_bl && e_br) { lineList.AddSegment(bl, br); } else if (e_bl) { lineList.AddSegment(bl, bc); } else if (e_br) { lineList.AddSegment(bc, br); } // Right if (e_rt && e_rb) { lineList.AddSegment(tr, br); } else if (e_rt) { lineList.AddSegment(tr, cr); } else if (e_rb) { lineList.AddSegment(cr, br); } // Right top out diagonals if (con_8l) { lineList.AddSegment(tc, new Coordinate(xMin + (x + 1)*width, yMax - (y + 1 + 0.5)*height)); } if (con_8r) { lineList.AddSegment(cr, new Coordinate(xMin + (x + 1 + 0.5) * width, yMax - (y + 1) * height)); } // Right in diagonals if (con_4l || con_8l) { if (!con_6r && !con_6l && !con_7 && !con_5) { lineList.AddSegment(tc, cl); } } if (con_4r || con_8r) { if (!con_2r && !con_2l && !con_1 && !con_3) { lineList.AddSegment(cr, bc); } } // Left Top out diagonals if (con_6r) { lineList.AddSegment(tc, new Coordinate(xMin + x*width, yMax - (y + 1 + 0.5)*height)); } if (con_6l) { lineList.AddSegment(cl, new Coordinate(xMin + (x - 0.5) * width, yMax - (y + 1) * height)); } // Left In diagonals if (con_6r || con_2r) { if (!con_8r && !con_8l && !con_7 && !con_1) { lineList.AddSegment(tc, cr); } } if (con_6l || con_2l) { if (!con_4r && !con_4l && !con_5 && !con_3) { lineList.AddSegment(cl, bc); } } if (cancelProgressHandler.Cancel) { return false; } } } var sw = new Stopwatch(); foreach (var pair in featureHash) { sw.Restart(); var key = pair.Key; var lineSegList = pair.Value.List; var polyList = new List<Polygon>(); var ind = 0; while (ind != lineSegList.Count) { var polyShell = new List<Coordinate>(); var start = lineSegList[ind++]; polyShell.Add(start.P0); polyShell.Add(start.P1); while (!polyShell[0].Equals2D(polyShell[polyShell.Count - 1])) { var last = polyShell[polyShell.Count - 1]; LineSegment segment = null; for (int i = ind; i < lineSegList.Count; i++) { var cur = lineSegList[i]; if (cur.P0.Equals2D(last) || cur.P1.Equals2D(last)) { segment = cur; if (ind != i) { var swap = lineSegList[ind]; lineSegList[ind] = cur; lineSegList[i] = swap; } ind++; break; } } Debug.Assert(segment != null); polyShell.Add(segment.P0.Equals2D(last) ? segment.P1 : segment.P0); } polyList.Add(new Polygon(polyShell)); } var geometry = polyList.Count == 1 ? (IBasicGeometry)polyList[0] : new MultiPolygon(polyList.ToArray()); var f = output.AddFeature(geometry); f.DataRow["Value"] = key; sw.Stop(); Debug.WriteLine(sw.ElapsedMilliseconds); } output.AttributesPopulated = true; output.Save(); return true; }
/// <summary> /// Create polygons from raster. /// </summary> /// <param name="input">The Polygon Raster(Grid file).</param> /// <param name="connectionGrid">Connection Grid.</param> /// <param name="output">The Polygon shapefile path.</param> /// <param name="cancelProgressHandler">The progress handler.</param> public bool Execute(IRaster input, IRaster connectionGrid, IFeatureSet output, ICancelProgressHandler cancelProgressHandler) { if (input == null || output == null) { return(false); } output.DataTable.Columns.Add("Value", typeof(double)); var featureHash = new Dictionary <double, LineSegmentList>(); var previous = 0.0; var height = input.CellHeight; var width = input.CellWidth; var xMin = input.Xllcenter - width / 2.0; var yMin = input.Yllcenter - height / 2.0; var xMax = xMin + width * input.NumColumns; var yMax = yMin + height * input.NumRows; var numRows = input.NumRows; var numColumns = input.NumColumns; Func <int, int, double, bool> same = (y, x, value) => y >= 0 && y < numRows && x >= 0 && x < numColumns && input.Value[y, x] == value; Func <int, int, double> get = (y, x) => y >= 0 && y < numRows && x >= 0 && x < numColumns ? input.Value[y, x] : input.NoDataValue; Func <int, int, int, int, bool> eqValues = (y1, x1, y2, x2) => get(y1, x1) == get(y2, x2); var enableCon = connectionGrid != null; Func <int, int, int> connection = (y, x) => enableCon ? (int)connectionGrid.Value[y, x] : 0; for (int y = 0; y < numRows; y++) { int current = Convert.ToInt32((y * 100.0) / input.NumRows); if (current > previous) { cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted); previous = current; } Debug.WriteLine("Row : " + y + " done."); for (int x = 0; x < numColumns; x++) { var value = input.Value[y, x]; if (value == input.NoDataValue) { continue; } LineSegmentList lineList; if (!featureHash.TryGetValue(value, out lineList)) { lineList = new LineSegmentList(); featureHash.Add(value, lineList); } var curCon = connection(y, x); /* * 6 7 8 * 5 0 1 * 4 3 2 * current cell (x,y)=0 */ var con_7 = same(y + 1, x, value); var con_5 = same(y, x - 1, value); var con_3 = same(y - 1, x, value); var con_1 = same(y, x + 1, value); var con_8l = enableCon && same(y + 1, x + 1, value) && !con_7 && (curCon == 8 || connection(y + 1, x + 1) == 4); var con_8r = enableCon && same(y + 1, x + 1, value) && !con_1 && (curCon == 8 || connection(y + 1, x + 1) == 4); var con_6l = enableCon && same(y + 1, x - 1, value) && !con_5 && (curCon == 6 || connection(y + 1, x - 1) == 2); var con_6r = enableCon && same(y + 1, x - 1, value) && !con_7 && (curCon == 6 || connection(y + 1, x - 1) == 2); var con_4l = enableCon && same(y - 1, x - 1, value) && !con_5 && (curCon == 4 || connection(y - 1, x - 1) == 8); var con_4r = enableCon && same(y - 1, x - 1, value) && !con_3 && (curCon == 4 || connection(y - 1, x - 1) == 8); var con_2l = enableCon && same(y - 1, x + 1, value) && !con_3 && (curCon == 2 || connection(y - 1, x + 1) == 6); var con_2r = enableCon && same(y - 1, x + 1, value) && !con_1 && (curCon == 2 || connection(y - 1, x + 1) == 6); /* Cell points: * tl tc tr * cl cr * bl bc br */ var tl = new Coordinate(xMin + x * width, yMax - (y + 1) * height); var tc = new Coordinate(xMin + (x + 0.5) * width, yMax - (y + 1) * height); var tr = new Coordinate(xMin + (x + 1) * width, yMax - (y + 1) * height); var cl = new Coordinate(xMin + x * width, yMax - (y + 0.5) * height); var cr = new Coordinate(xMin + (x + 1) * width, yMax - (y + 0.5) * height); var bl = new Coordinate(xMin + x * width, yMax - y * height); var bc = new Coordinate(xMin + (x + 0.5) * width, yMax - y * height); var br = new Coordinate(xMin + (x + 1) * width, yMax - y * height); /* * Cell edges: * e_tl e_tr * ----|---- * e_lt | | e_rt * - - * e_lb | | e_rb * ----|---- * e_bl e_br */ bool e_tr = false, e_tl = false, e_lt = false, e_lb = false, e_rt = false, e_rb = false, e_br = false, e_bl = false; if (!con_7) { #region Check Cell 7 // top: right half if (!con_8l) { var a1 = con_6r && con_1; var a2 = !con_8r && !con_6l && con_4l && !con_2r; e_tr = a1 || a2; } // top: left half if (!con_6r) { var a1 = con_8l && con_5; var a2 = !con_8r && !con_6l && !con_4l && con_2r; e_tl = a1 || a2; } // top: full if (!con_8l && !con_6r && !con_4l && !con_2r) { e_tr = e_tl = true; } #endregion } if (!con_3) { #region Check Cell 3 // bottom: left half if (!con_4r) { var a1 = con_2l && con_5; var a2 = !con_2r && !con_4l && !con_6l && con_8r; e_bl = a1 || a2; } // bottom: right half if (!con_2l) { var a1 = con_4r && con_1; var a2 = !con_2r && !con_4l && !con_8r && con_6l; e_br = a1 || a2; } // bottom: full if (!con_4r && !con_2l && !con_8r && !con_6l) { e_bl = e_br = true; } #endregion } if (!con_1) { #region Check Cell 1 // right: bottom half if (!con_2r) { var a1 = con_8r && con_3; var a2 = !con_2l && !con_8l && !con_4r && con_6r; e_rb = a1 || a2; } // right: top half if (!con_8r) { var a1 = con_2r && con_7; var a2 = !con_2l && !con_8l && !con_6r && con_4r; e_rt = a1 || a2; } // right: full if (!con_2r && !con_8r && !con_4r && !con_6r) { e_rb = e_rt = true; } #endregion } if (!con_5) { #region Check Cell 5 // left: bottom half if (!con_4l) { var a1 = con_3 && con_6l; var a2 = !con_6r && !con_4r && con_8l && !con_2l; e_lb = a1 || a2; } // left: top half if (!con_6l) { var a1 = con_4l && con_7; var a2 = !con_6r && !con_4r && !con_8l && con_2l; e_lt = a1 || a2; } // left: full if (!con_4l && !con_6l && !con_8l && !con_2l) { e_lb = e_lt = true; } #endregion } // Smooth boundaries regarding to outer cells // Right top corner if (e_tr && e_rt) { if (eqValues(y + 1, x, y, x + 1)) { var a1 = connection(y + 1, x); var a2 = connection(y, x + 1); if ((a1 == 6 || a1 == 2 || a2 == 6 || a2 == 2) && !(a1 == 6 && a2 == 2)) { lineList.AddSegment(tc, cr); e_tr = e_rt = false; } } } // Left top corner if (e_tl && e_lt) { if (eqValues(y, x - 1, y + 1, x)) { var a1 = connection(y, x - 1); var a2 = connection(y + 1, x); if ((a1 == 8 || a1 == 4 || a2 == 8 || a2 == 4) && !(a1 == 8 && a2 == 4)) { lineList.AddSegment(tc, cl); e_tl = e_lt = false; } } } // Left bottom corner if (e_bl && e_lb) { if (eqValues(y - 1, x, y, x - 1)) { var a1 = connection(y - 1, x); var a2 = connection(y, x - 1); if ((a1 == 6 || a1 == 2 || a2 == 6 || a2 == 2) && !(a1 == 6 && a2 == 2)) { lineList.AddSegment(cl, bc); e_bl = e_lb = false; } } } // Right bottom corner if (e_br && e_rb) { if (eqValues(y, x + 1, y - 1, x)) { var a1 = connection(y, x + 1); var a2 = connection(y - 1, x); if ((a1 == 8 || a1 == 4 || a2 == 8 || a2 == 4) && !(a1 == 8 && a2 == 4)) { lineList.AddSegment(bc, cr); e_br = e_rb = false; } } } // Smooth boundaries regarding direction of current cell switch (curCon) { case 2: case 6: if (e_tr && e_rt) { lineList.AddSegment(tc, cr); e_tr = e_rt = false; } if (e_bl && e_lb) { lineList.AddSegment(bc, cl); e_bl = e_lb = false; } break; case 4: case 8: if (e_tl && e_lt) { lineList.AddSegment(cl, tc); e_tl = e_lt = false; } if (e_br && e_rb) { lineList.AddSegment(cr, bc); e_br = e_rb = false; } break; } // Add remaining edges // Top if (e_tl && e_tr) { lineList.AddSegment(tl, tr); } else if (e_tl) { lineList.AddSegment(tl, tc); } else if (e_tr) { lineList.AddSegment(tc, tr); } //Left if (e_lt && e_lb) { lineList.AddSegment(tl, bl); } else if (e_lt) { lineList.AddSegment(tl, cl); } else if (e_lb) { lineList.AddSegment(cl, bl); } // Bottom if (e_bl && e_br) { lineList.AddSegment(bl, br); } else if (e_bl) { lineList.AddSegment(bl, bc); } else if (e_br) { lineList.AddSegment(bc, br); } // Right if (e_rt && e_rb) { lineList.AddSegment(tr, br); } else if (e_rt) { lineList.AddSegment(tr, cr); } else if (e_rb) { lineList.AddSegment(cr, br); } // Right top out diagonals if (con_8l) { lineList.AddSegment(tc, new Coordinate(xMin + (x + 1) * width, yMax - (y + 1 + 0.5) * height)); } if (con_8r) { lineList.AddSegment(cr, new Coordinate(xMin + (x + 1 + 0.5) * width, yMax - (y + 1) * height)); } // Right in diagonals if (con_4l || con_8l) { if (!con_6r && !con_6l && !con_7 && !con_5) { lineList.AddSegment(tc, cl); } } if (con_4r || con_8r) { if (!con_2r && !con_2l && !con_1 && !con_3) { lineList.AddSegment(cr, bc); } } // Left Top out diagonals if (con_6r) { lineList.AddSegment(tc, new Coordinate(xMin + x * width, yMax - (y + 1 + 0.5) * height)); } if (con_6l) { lineList.AddSegment(cl, new Coordinate(xMin + (x - 0.5) * width, yMax - (y + 1) * height)); } // Left In diagonals if (con_6r || con_2r) { if (!con_8r && !con_8l && !con_7 && !con_1) { lineList.AddSegment(tc, cr); } } if (con_6l || con_2l) { if (!con_4r && !con_4l && !con_5 && !con_3) { lineList.AddSegment(cl, bc); } } if (cancelProgressHandler.Cancel) { return(false); } } } foreach (var pair in featureHash) { #if DEBUG var sw = new Stopwatch(); sw.Start(); #endif var key = pair.Key; var lineSegList = pair.Value.List; var polyList = new List <IPolygon>(); var ind = 0; while (ind != lineSegList.Count) { var polyShell = new List <Coordinate>(); var start = lineSegList[ind++]; polyShell.Add(start.P0); polyShell.Add(start.P1); while (!polyShell[0].Equals2D(polyShell[polyShell.Count - 1])) { var last = polyShell[polyShell.Count - 1]; LineSegment segment = null; for (int i = ind; i < lineSegList.Count; i++) { var cur = lineSegList[i]; if (cur.P0.Equals2D(last) || cur.P1.Equals2D(last)) { segment = cur; if (ind != i) { var swap = lineSegList[ind]; lineSegList[ind] = cur; lineSegList[i] = swap; } ind++; break; } } Debug.Assert(segment != null); polyShell.Add(segment.P0.Equals2D(last) ? segment.P1 : segment.P0); } polyList.Add(new Polygon(new LinearRing(polyShell.ToArray()))); } IGeometry geometry = polyList.Count == 1 ? (IGeometry)polyList[0] : new MultiPolygon(polyList.ToArray()); var f = output.AddFeature(geometry); f.DataRow["Value"] = key; #if DEBUG sw.Stop(); Debug.WriteLine(sw.ElapsedMilliseconds); #endif } output.AttributesPopulated = true; output.Save(); return(true); }
private void M_DotMap_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (m_AddFeaType != FeaType.None) { Coordinate coord = m_DotMap.PixelToProj(e.Location);//点击的屏幕未知转换成坐标系中的点 switch (m_AddFeaType) { case FeaType.Point: { CreatePointDlg f = UCVectorDataEditing.m_CreatePointDlg; if (f == null) { return; } var layer = f.m_PointLayer; IFeatureSet PointF = (layer as FeatureLayer).FeatureSet; GeoAPI.Geometries.IPoint pPoint = new NetTopologySuite.Geometries.Point(coord); IFeature currentFeature = PointF.AddFeature(pPoint); PointF.InitializeVertices(); m_DotMap.ResetBuffer(); } break; case FeaType.Polyline: { CreatePolylineDlg f = UCVectorDataEditing.m_CreatePolylineDlg; if (f == null) { return; } var layer = f.m_PolylineLayer; IFeatureSet LineF = (layer as FeatureLayer).FeatureSet; if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (f.IsFirstPoint) { //一开始就要加入至少两个点 f.CoordList.Add(coord); f.CoordList.Add(coord); LineString line = new LineString(f.CoordList.ToArray()); IFeature lineFeature = LineF.AddFeature(line); f.IsFirstPoint = false; } else { LineF.Features.RemoveAt(LineF.Features.Count - 1); if (f.CoordList[0] == f.CoordList[1]) { f.CoordList.RemoveAt(1); } f.CoordList.Add(coord); LineString line = new LineString(f.CoordList.ToArray()); IFeature lineFeature = LineF.AddFeature(line); m_DotMap.ResetBuffer(); } } else if (e.Button == System.Windows.Forms.MouseButtons.Right) { LineF.InitializeVertices(); f.IsFirstPoint = true; f.CoordList.Clear(); m_DotMap.ResetBuffer(); } } break; case FeaType.Polygon: { CreatePolygonDlg f = UCVectorDataEditing.m_CreatePolygonDlg; if (f == null) { return; } var layer = f.m_PolygonLayer; IFeatureSet PolygonF = (layer as FeatureLayer).FeatureSet; if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (f.IsFirstPoint) { for (int i = 0; i < 4; i++) { f.CoordList.Add(coord); } ILinearRing LineRing = new LinearRing(f.CoordList.ToArray()); NetTopologySuite.Geometries.Polygon pPolygon = new NetTopologySuite.Geometries.Polygon(LineRing); IFeature polygonFeature = PolygonF.AddFeature(pPolygon); f.IsFirstPoint = false; } else { PolygonF.Features.RemoveAt(PolygonF.Features.Count - 1); if (f.CoordList[0] == f.CoordList[1]) { f.CoordList.RemoveAt(1); } //组成面的点必须形成一个闭环 因此要先把最新加入的点去掉,加入绘制点之后再加入第一个点 f.CoordList.RemoveAt(f.CoordList.Count - 1); f.CoordList.Add(coord); f.CoordList.Add(f.CoordList[0]); ILinearRing LineRing = new LinearRing(f.CoordList.ToArray()); NetTopologySuite.Geometries.Polygon pPolygon = new NetTopologySuite.Geometries.Polygon(LineRing); IFeature lineFeature = PolygonF.AddFeature(pPolygon); m_DotMap.ResetBuffer(); } } else if (e.Button == System.Windows.Forms.MouseButtons.Right) { PolygonF.InitializeVertices(); f.IsFirstPoint = true; f.CoordList.Clear(); m_DotMap.ResetBuffer(); } } break; } } }
private void UpdateLocalitiesGisData(IFeatureSet dataset) { foreach (var locality in context.Localities) { if (string.IsNullOrEmpty(locality.Code) || locality.Location == null) continue; var coord = new Coordinate(locality.Location.Longitude ?? 0, locality.Location.Latitude ?? 0); var feature = dataset.AddFeature(new Point(coord)); feature.DataRow["Code"] = locality.Code; } }
private void UpdateFrequenciesGisData(IFeatureSet dataset) { dataset.DataTable.Columns.Add(new DataColumn("Frequency", typeof (double))); dataset.DataTable.Columns.Add(new DataColumn("Dimension", typeof (string))); if (selectedAnalysis == null) return; if (string.IsNullOrEmpty(dimension)) return; foreach (var frequency in selectedAnalysis.Frequencies) { if (!frequency.Name.StartsWith(dimension)) continue; var location = frequency.Locality.Location; if (location == null) continue; //should it instead skip the locality if part of the coordinate is missing? var coord = new Coordinate(location.Longitude ?? 0, location.Latitude ?? 0); var feature = dataset.AddFeature(new Point(coord)); feature.DataRow["Code"] = frequency.Locality.Code; feature.DataRow["Frequency"] = frequency.Value; feature.DataRow["Dimension"] = frequency.Name; } }
private void BtnConform_Click(object sender, EventArgs e) { ///로드 시작 IMapLayer layer = null; if (_allWTLayerBtns.Cast <RadioButtonAdv>().FirstOrDefault(x => x.Checked).Text != "기타") { ///매핑 완료 체크 if (_stdColumnCnts != _mappingCnts) { MessageBox.Show("모든 표준 속성이 매핑 완료된 후" + "\n진행할 수 있습니다." , base.MmakerShell.AppTitle); return; } ///선택 레이어를 표준 WTL레이어로 변환한다. IFeatureSet cfs = CurrentFeatureSet(); if (cfs == null) { MessageBox.Show("표준 레이어에 등록되지 않은 레이어입니다." , base.MmakerShell.AppTitle); return; } ///[20200323] fdragons - 표준 레이어가 이미 로드되어 있으면 합칠 것인지 확인한다. var v = MmakerShell.AppManager.Map.Layers.FirstOrDefault(x => x.DataSet?.Name == cfs.Name); if (v != null) { layer = v; if (DialogResult.Yes != MessageBox.Show($"[{cfs.Name}]" + "\n표준 레이어는 이미 로드되어 있습니다." + "\n기존 레이어에 추가 하시겠습니까?" , base.MmakerShell.AppTitle , MessageBoxButtons.YesNo)) { MessageBox.Show($"[{cfs.Name}]" + "\n선택한 레이어는 중복하여 등록할 수 없습니다." , base.MmakerShell.AppTitle, MessageBoxButtons.YesNo); return; } } ///1. 컬럼 매핑정보 읽기 DataTable dataTable = ((IFeatureSet)_orgData).DataTable; try { for (int i = 0; i < lstMappedCols.Items.Count; i++) { ///2. 매핑정보를 이용하여 _orgData의 컬럼명을 표준 컬럼명으로 이름변경 bool a = GetFieldNameInlstMappedColsUsingIndex(i, out string szOrg, out string szStd); if (szOrg.Equals("*None*")) { continue; } /// 표준 명칭이 기 존재하면 스킵 if (IsFieldUsedInlstMappedCols(2, szStd)) { continue; } dataTable.Columns[szOrg].ColumnName = szStd; } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw; } ///3. 선택된 레이어 데이터를 표준레이어로 복제한다. try { foreach (IFeature f in ((IFeatureSet)_orgData).Features) { IFeature nf = cfs.AddFeature(f.Geometry); nf.CopyAttributes(f); } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw; } ///4. 복제된 레이어를 등록한다. if (layer == null) { layer = MmakerShell.AppManager.Map.Layers.Add(cfs); } } else { ///[20200323] fdragons - 동일 이름의 레이어가 이미 로드되어 있으면 합칠 것인지 확인한다. var v = MmakerShell.AppManager.Map.Layers.FirstOrDefault(x => x.DataSet?.Name == _orgData.Name); if (v != null) { layer = v; if (DialogResult.Yes != MessageBox.Show($"[{_orgData.Name}]" + "\n동일 레이어가 존재합니다." + "\n기존 레이어에 추가 하시겠습니까?" , base.MmakerShell.AppTitle , MessageBoxButtons.YesNo)) { MessageBox.Show($"[{_orgData.Name}]" + "\n선택한 레이어는 등록할 수 없습니다." , base.MmakerShell.AppTitle, MessageBoxButtons.YesNo); return; } ///[20200323] fdragons 선택된 레이어 데이터를 표준레이어로 복제한다. try { var fcs = (IFeatureSet)layer.DataSet; foreach (IFeature f in ((IFeatureSet)_orgData).Features) { IFeature nf = fcs.AddFeature(f.Geometry); nf.CopyAttributes(f); } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw; } } else { ///참조용 레이어로 추가한다. layer = MmakerShell.AppManager.Map.Layers.Add((IFeatureSet)_orgData); } } ///[20200320] fdragons - 레이어 영역 업데이트 if (layer != null) { layer.Extent.ExpandToInclude(((IFeatureSet)_orgData).Extent); ZoomToLayer(layer); } MmakerShell.AppManager.Map.Refresh(); DialogResult = DialogResult.OK; this.Close(); }