protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers) { // Draw shape like area and point base.DrawCore(canvas, labelsInAllLayers); // Draw annotation label if (!ZoomLevelSet.CustomZoomLevels.Any(z => z.CustomStyles.OfType <CompositeStyle>().SelectMany(c => c.Styles).Any(s => s is TextStyle))) { Collection <Feature> annotationFeatures = ((TobinBasFeatureSource)FeatureSource).AnnotationFeatures; foreach (var item in annotationFeatures) { float textSize = float.Parse(item.ColumnValues["TextSize"].ToString()); double latDiff = DecimalDegreesHelper.GetLatitudeDifferenceFromDistance(textSize, DistanceUnit.Feet); PointShape startPoint = (PointShape)item.GetShape(); PointShape endPoint = new PointShape(startPoint.X, startPoint.Y + latDiff); float fontSize = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, startPoint, canvas.Width, canvas.Height).Y - ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, endPoint, canvas.Width, canvas.Height).Y; if (fontSize > minAnnotationFontSize) { TextStyle textStyle = new TextStyle("TextString", new GeoFont(), new GeoSolidBrush(GeoColor.SimpleColors.Black)); textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels; textStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping; textStyle.YOffsetInPixel = 1 * fontSize; textStyle.RotationAngle = double.Parse(item.ColumnValues["TextAngle"]); textStyle.Font = new GeoFont("Arial", fontSize); textStyle.Draw(new Collection <Feature> { item }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers); } } } }
private float GetPointSize(GeoCanvas canvas) { // Calculate the size of the points in pixel based on the world point size and the current extent. //Gets the proper point size according to the current extent. (meter is used as base unit) double canvasSizeMeter; double pointSizeMeter = Conversion.ConvertMeasureUnits(pointSize, pointSizeUnit, DistanceUnit.Meter); //if the mapunit is in Decimal Degrees, it uses a different logic than with other mapunits such as meters and feet. if (canvas.MapUnit == GeographyUnit.DecimalDegree) { try { canvasSizeMeter = DecimalDegreesHelper.GetDistanceFromDecimalDegrees(canvas.CurrentWorldExtent.UpperLeftPoint.X, canvas.CurrentWorldExtent.UpperLeftPoint.Y, canvas.CurrentWorldExtent.LowerLeftPoint.X, canvas.CurrentWorldExtent.LowerLeftPoint.Y, DistanceUnit.Meter); } catch { canvasSizeMeter = DecimalDegreesHelper.GetDistanceFromDecimalDegrees(180, 90, 180, -90, DistanceUnit.Meter); } finally { } } else { DistanceUnit fromUnit = DistanceUnit.Meter; if (canvas.MapUnit == GeographyUnit.Feet) { fromUnit = DistanceUnit.Feet; } canvasSizeMeter = Conversion.ConvertMeasureUnits(canvas.CurrentWorldExtent.Height, fromUnit, DistanceUnit.Meter); } float size = (float)((pointSizeMeter * canvas.Height) / canvasSizeMeter); return(size); }
private void ConvertCoordinates() { Proj4Projection proj4 = new Proj4Projection(); proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); proj4.ExternalProjectionParametersString = GisEditor.ActiveMap.DisplayProjectionParameters; double x = 0; double y = 0; switch (SelectedCoordinateFormat) { case CoordinateType.DegreesMinutes: case CoordinateType.DegreesMinutesSeconds: if (String.IsNullOrEmpty(LatitudeSeconds)) { LatitudeSeconds = "0"; } if (String.IsNullOrEmpty(LongitudeSeconds)) { LongitudeSeconds = "0"; } double yDegrees, yMinutes, xDegrees, xMinutes, ySeconds, xSeconds; if (double.TryParse(LatitudeDegrees, out yDegrees) && double.TryParse(LatitudeMinutes, out yMinutes) && double.TryParse(LatitudeSeconds, out ySeconds) && double.TryParse(LongitudeDegrees, out xDegrees) && double.TryParse(LongitudeMinutes, out xMinutes) && double.TryParse(LongitudeSeconds, out xSeconds) ) { double actualXMinutes = xMinutes + (xDegrees - (int)xDegrees) * 60; double actualXSeconds = xSeconds + (actualXMinutes - (int)actualXMinutes) * 60; double actualYMinutes = yMinutes + (yDegrees - (int)yDegrees) * 60; double actualYSeconds = ySeconds + (actualYMinutes - (int)actualYMinutes) * 60; x = DecimalDegreesHelper.GetDecimalDegreeFromDegreesMinutesSeconds((int)xDegrees, (int)actualXMinutes, actualXSeconds); y = DecimalDegreesHelper.GetDecimalDegreeFromDegreesMinutesSeconds((int)yDegrees, (int)actualYMinutes, actualYSeconds); x = LongitudeType == "E" ? x : -x; y = LatitudeType == "N" ? y : -y; } else { throw new Exception(errorMessage); } break; case CoordinateType.XY: case CoordinateType.DecimalDegrees: default: if (!(double.TryParse(Longitude, out x) && double.TryParse(Latitude, out y))) { throw new Exception(errorMessage); } break; } proj4.Open(); ResultVertex = SelectedCoordinateFormat == CoordinateType.XY ? new Vertex(x, y) : proj4.ConvertToExternalProjection(x, y); proj4.Close(); }
void timer_Tick(object sender, EventArgs e) { //Gets the GPS info from the textfile. DataTable carData = GetCarData(); float angleOffset; double angle; LayerOverlay dynamicOverlay = (LayerOverlay)winformsMap1.Overlays["DynamicOverlay"]; InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["CarLayer"]; //InMemoryFeatureLayer labelInMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["CarLabel"]; PointShape pointShape = inMemoryFeatureLayer.InternalFeatures[0].GetShape() as PointShape; // Get the Row of Data we are working with. DataRow carDataRow = carData.Rows[0]; double Lat = Convert.ToDouble(carDataRow["LAT"]); double Long = Convert.ToDouble(carDataRow["LONG"]); //Gets the angle based on the current GPS position and the previous one to get the direction of the vehicle. angle = GetAngleFromTwoVertices(new Vertex(previousLong, previousLat), new Vertex(Long, Lat)); //Gets the correct icon depending on the direction of the vehicle. if (previousLong < Long) { inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = carGeoImageDown; angleOffset = 180; } else { inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = carGeoImageUp; angleOffset = 360; } inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.RotationAngle = angleOffset - (float)angle; pointShape.X = Long; pointShape.Y = Lat; pointShape.Id = "Car"; //Updates the column "VehiclePosition" of the feature to the current Longitude/Latitude. Feature feature = inMemoryFeatureLayer.InternalFeatures[0]; feature.ColumnValues["VehiclePosition"] = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(pointShape); //Updates the PointShape of the Feature. inMemoryFeatureLayer.Open(); inMemoryFeatureLayer.EditTools.BeginTransaction(); inMemoryFeatureLayer.EditTools.Update(pointShape); inMemoryFeatureLayer.EditTools.CommitTransaction(); inMemoryFeatureLayer.Close(); previousLong = Long; previousLat = Lat; winformsMap1.Refresh(dynamicOverlay); }
//Formats the decimal degree value into Degree Minute and Seconds according to the increment. It also looks //if the longitude is East or West and the latitude North or South. private string FormatLatLong(double value, LineType lineType, double increment) { string result = ""; try { if (increment >= 1) { result = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(Math.Abs(value)); result = result.Substring(0, result.Length - 9); } else if (increment >= 0.1) { result = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(Math.Abs(value)); result = result.Substring(0, result.Length - 5); } else if (increment >= 0.01) { result = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(Math.Abs(value)); } else { result = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(Math.Abs(value), 2); } if (lineType == LineType.Meridian) { if (value > 0) { result = result + " E"; } else if (value < 0) { result = result + " W"; } } if (lineType == LineType.Parallel) { if (value > 0) { result = result + " N"; } else if (value < 0) { result = result + " S"; } } } catch { result = "N/A"; } finally {} return(result); }
private void ShowCoordinate(MouseEventArgs e) { PointShape WorldPointR = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, e.X, e.Y, winformsMap1.Width, winformsMap1.Height); statusStrip.Items[1].Text = string.Format(CultureInfo.InvariantCulture, "X: {0:F4} Y: {1:F4}", WorldPointR.X, WorldPointR.Y); statusStrip.Items[2].Text = string.Format(CultureInfo.InvariantCulture, "X: {0} Y: {1}", e.X, e.Y); if (winformsMap1.MapUnit == GeographyUnit.DecimalDegree && ((WorldPointR.X > -180 && WorldPointR.X < 180 && WorldPointR.Y > -90 && WorldPointR.Y < 90))) { statusStrip.Items[0].Text = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(WorldPointR); return; } statusStrip.Items[0].Text = ""; }
//Displays the world coordinates for the mouse pointer in decimal degrees and Degrees Minutes Seconds form. private void winformsMap1_MouseMove(object sender, MouseEventArgs e) { PointShape worldPointShape = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, new ScreenPointF(e.X, e.Y), winformsMap1.Width, winformsMap1.Height); try { lblLongitudeDMS.Text = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(worldPointShape.X); lblLatitudeDMS.Text = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(worldPointShape.Y); lblLongitude.Text = System.Convert.ToString(worldPointShape.X); lblLatitude.Text = System.Convert.ToString(worldPointShape.Y); } catch { lblLongitudeDMS.Text = "N/A"; lblLatitudeDMS.Text = "N/A"; lblLongitude.Text = "N/A"; lblLatitude.Text = "N/A"; } finally { } }
private void TestForm_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.Meter; winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255)); GoogleMapsOverlay googleOverlay = new GoogleMapsOverlay(); //(@"Insert your key here!", @"C:\GoogleCache"); googleOverlay.MapType = GoogleMapsMapType.Terrain; winformsMap1.Overlays.Add(googleOverlay); // This sets the zoom levels to map to Googles. We next make sure we snap to the zoomlevels winformsMap1.ZoomLevelSet = new GoogleMapsZoomLevelSet(); InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer(); pointLayer.Open(); pointLayer.Columns.Add(new FeatureSourceColumn("Text")); pointLayer.Close(); //Sets the projection parameters to go from Geodetic (EPSG 4326) or decimal degrees to Google Map projection (Spherical Mercator). Proj4Projection proj4 = new Proj4Projection(); proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); //Applies the projection to the InMemoryFeatureLayer so that the point in decimal degrees (Longitude/Latitude) can be //match the projection of Google Map. pointLayer.FeatureSource.Projection = proj4; //Values in Longitude and Latitude. double Longitude = -95.2809; double Latitude = 38.9543; //Creates the feature made of a PointShape with the Longitude and Latitude values. Feature GPSFeature = new Feature(new PointShape(Longitude, Latitude)); //Format the Longitude and Latitude into a nice string as Degrees Minutes and Seconds string LongLat = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(GPSFeature); //Sets the InMemoryFeatureLayer to have it displayed with Square symbol and with text. GPSFeature.ColumnValues.Add("Text", LongLat); pointLayer.InternalFeatures.Add(GPSFeature); pointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Square, GeoColor.StandardColors.Red, GeoColor.StandardColors.Black, 2, 12); pointLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("Text", "Arial", 12, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, GeoColor.StandardColors.White, 3, -10, 10); pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; LayerOverlay pointOverlay = new LayerOverlay(); pointOverlay.Layers.Add("PointLayer", pointLayer); winformsMap1.Overlays.Add("PointOverlay", pointOverlay); //Sets the extend of the map based on the GPS point. proj4.Open(); Vertex projVertex = proj4.ConvertToExternalProjection(Longitude, Latitude); proj4.Close(); double extendWidth = 2300; double extendHeight = 1200; winformsMap1.CurrentExtent = new RectangleShape((projVertex.X - extendWidth), (projVertex.Y + extendHeight), (projVertex.X + extendWidth), (projVertex.Y - extendHeight)); winformsMap1.Refresh(); }
internal static double GetEvaluatedDistance(Vertex point1, PointShape point2) { return(DecimalDegreesHelper.GetDistanceFromDecimalDegrees(new PointShape(point1), point2, DistanceUnit.Meter)); }
private void InitGridDefinition() { var entity = content.DataContext as GridWizardShareObject; RectangleShape gridExtent = new RectangleShape(); List <Feature> features = new List <Feature>(); entity.SelectedFeatureLayer.SafeProcess(() => { if (entity.HasSelectedFeatures && entity.OnlyUseSelectedFeatures) { features = GisEditor.SelectionManager.GetSelectedFeatures().Where(f => f.Tag != null && f.Tag == entity.SelectedFeatureLayer).ToList(); gridExtent = ExtentHelper.GetBoundingBoxOfItems(features); gridExtent.ScaleUp(0.05); } else { features = entity.SelectedFeatureLayer.FeatureSource.GetAllFeatures(entity.SelectedFeatureLayer.FeatureSource.GetDistinctColumnNames()).ToList(); gridExtent = ExtentHelper.GetBoundingBoxOfItems(features); } }); Dictionary <PointShape, double> dataPoints = new Dictionary <PointShape, double>(); foreach (var item in features) { double columnValue = double.NaN; if (double.TryParse(item.ColumnValues[entity.SelectedDataColumn.ColumnName], out columnValue)) { var shape = item.GetShape(); if (shape.GetType().Equals(typeof(MultipointShape))) { foreach (var point in ((MultipointShape)shape).Points) { point.Tag = null; dataPoints.Add(point, columnValue); } } else { PointShape pointShape = (PointShape)shape; pointShape.Tag = null; dataPoints.Add(pointShape, columnValue); } } } double tmpCellSize = 0.0; switch (GisEditor.ActiveMap.MapUnit) { case GeographyUnit.DecimalDegree: tmpCellSize = DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(entity.CellSize, entity.SelectedCellSizeDistanceUnit, gridExtent.GetCenterPoint().Y); break; case GeographyUnit.Feet: tmpCellSize = Conversion.ConvertMeasureUnits(entity.CellSize, entity.SelectedCellSizeDistanceUnit, DistanceUnit.Feet); break; case GeographyUnit.Meter: tmpCellSize = Conversion.ConvertMeasureUnits(entity.CellSize, entity.SelectedCellSizeDistanceUnit, DistanceUnit.Meter); break; default: break; } entity.GridDefinition = new GridDefinition(gridExtent, tmpCellSize, -9999, dataPoints); }