private IPoint GetMapPoint(int X, int Y) { if ((ArcMap.Document == null) || (ArcMap.Document.FocusMap == null)) { return(null); } //Get the active view from the ArcMap static class. IActiveView activeView = (IActiveView)ArcMap.Document.FocusMap; var point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y) as IPoint; if (point == null) { return(null); } if (CoordinateConversionLibraryConfig.AddInConfig.DisplayCoordinateType == CoordinateConversionLibrary.CoordinateTypes.None || CoordinateConversionLibraryConfig.AddInConfig.DisplayCoordinateType == CoordinateConversionLibrary.CoordinateTypes.Default) { point.SpatialReference = ArcMap.Document.FocusMap.SpatialReference; } else { // always use WGS84 var sr = ArcMapHelpers.GetGCS_WGS_1984_SR(); if (sr != null) { point.Project(sr); } } return(point); }
private void OnNewMapPointSelection(object obj) { var point = obj as IPoint; if (point == null) { return; } var sr = ArcMapHelpers.GetGCS_WGS_1984_SR(); point.Project(sr); InputCoordinate = string.Format("{0:0.0####} {1:0.0####}", point.Y, point.X); }
private void AddCollectionPoint(IPoint point) { var color = new RgbColorClass() { Red = 255 } as IColor; var guid = ArcMapHelpers.AddGraphicToMap(point, color, true, esriSimpleMarkerStyle.esriSMSCircle, 7); var addInPoint = new AddInPoint() { Point = point, GUID = guid }; CoordinateAddInPoints.Add(addInPoint); GraphicsList.Add(new AMGraphic(guid, point, true)); }
private void AddCollectionPoint(IPoint point, Dictionary <string, Tuple <object, bool> > fieldsDictionary = null) { if (point != null && !point.IsEmpty) { var color = (IColor) new RgbColorClass() { Red = 255 }; var guid = ArcMapHelpers.AddGraphicToMap(point, color, true, esriSimpleMarkerStyle.esriSMSCircle, ArcMapHelpers.DefaultMarkerSize); var addInPoint = new AddInPoint() { Point = point, GUID = guid, FieldsDictionary = fieldsDictionary }; //Add point to the top of the list CoordinateAddInPoints.Add(addInPoint); GraphicsList.Add(new AMGraphic(guid, point, true, fieldsDictionary)); } }
private void AddCollectionPoint(IPoint point) { if (!point.IsEmpty && point != null) { var color = new RgbColorClass() { Red = 255 } as IColor; var guid = ArcMapHelpers.AddGraphicToMap(point, color, true, esriSimpleMarkerStyle.esriSMSCircle, 7); var addInPoint = new AddInPoint() { Point = point, GUID = guid }; //Add point to the top of the list CoordinateAddInPoints.Insert(0, addInPoint); GraphicsList.Add(new AMGraphic(guid, point, true)); } }
private void AddCollectionPoint(IPoint point) { if (point != null && !point.IsEmpty) { var color = new RgbColorClass() { Red = 255 } as IColor; var guid = ArcMapHelpers.AddGraphicToMap(point, color, true, esriSimpleMarkerStyle.esriSMSCircle, ArcMapHelpers.DefaultMarkerSize); var addInPoint = new AddInPoint() { Point = point, GUID = guid }; //Add point to the top of the list CollectTabViewModel.CoordinateAddInPoints.Add(addInPoint); CollectTabViewModel.GraphicsList.Add(new AMGraphic(guid, point, true)); } }
internal override void OnFlashPointCommand(object obj) { if ((ArcMap.Document == null) || (ArcMap.Document.ActiveView == null) || (ArcMap.Document.FocusMap == null)) { return; } ProcessInput(InputCoordinate); Mediator.NotifyColleagues(CoordinateConversionLibrary.Constants.RequestOutputUpdate, null); IGeometry address = obj as IGeometry; if (address == null && amCoordGetter != null && amCoordGetter.Point != null) { address = amCoordGetter.Point; AddCollectionPoint(amCoordGetter.Point); } if (address != null) { IActiveView activeView = ArcMap.Document.ActiveView; IMap map = ArcMap.Document.FocusMap; IEnvelope envelope = activeView.Extent; IScreenDisplay screenDisplay = activeView.ScreenDisplay; short screenCache = Convert.ToInt16(esriScreenCache.esriNoScreenCache); ISpatialReference outgoingCoordSystem = map.SpatialReference; address.Project(outgoingCoordSystem); // is point within current extent // if so, pan to point var relationOp = envelope as IRelationalOperator; if (relationOp != null && activeView is IMap) { if (!relationOp.Contains(address)) { // pan to envelope.CenterAt(address as IPoint); activeView.Extent = envelope; activeView.Refresh(); } } IRgbColor color = new RgbColorClass(); color.Green = 80; color.Red = 22; color.Blue = 68; ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(); simpleMarkerSymbol.Color = color; simpleMarkerSymbol.Size = 15; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond; IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = simpleMarkerSymbol; IPolygon poly = null; if (InputCoordinateType == CoordinateType.MGRS || InputCoordinateType == CoordinateType.USNG) { poly = GetMGRSPolygon(address as IPoint); } if (poly != null) { address = poly; } ArcMapHelpers.FlashGeometry(address, color, activeView.ScreenDisplay, 500, activeView.Extent); } }
private CoordinateType GetCoordinateType(string input, out ESRI.ArcGIS.Geometry.IPoint point) { point = new PointClass(); var cn = (IConversionNotation)point; Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); if (t == null) { return(CoordinateType.Unknown); } System.Object obj = Activator.CreateInstance(t); if (obj == null) { return(CoordinateType.Unknown); } ISpatialReferenceFactory srFact = obj as ISpatialReferenceFactory; if (srFact == null) { return(CoordinateType.Unknown); } // Use the enumeration to create an instance of the predefined object. IGeographicCoordinateSystem geographicCS = srFact.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984); point.SpatialReference = geographicCS; string numSep = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator; input = numSep != "." ? input.Replace(numSep, ".") : input; try { CoordinateDD dd; if (CoordinateDD.TryParse(input, out dd, true)) { // Reformat the string for cases where lat/lon have been switched // PutCoords calls fail if the double uses decimal separator other than a decimal point // Added InvariantCulture option to ensure the current culture is ignored string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1}", dd.Lat, dd.Lon); cn.PutCoordsFromDD(newInput); return(CoordinateType.DD); } } catch { /* Conversion Failed */ } try { CoordinateDDM ddm; if (CoordinateDDM.TryParse(input, out ddm, true)) { // Reformat the string for cases where lat/lon have been switched // PutCoords calls fail if the double uses decimal separator other than a decimal point // Added InvariantCulture option to ensure the current culture is ignored string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", ddm.LatDegrees, ddm.LatMinutes, ddm.LonDegrees, ddm.LonMinutes); cn.PutCoordsFromDD(newInput); return(CoordinateType.DDM); } } catch { /* Conversion Failed */ } try { CoordinateDMS dms; if (CoordinateDMS.TryParse(input, out dms, true)) { // Reformat the string for cases where lat/lon have been switched // PutCoords calls fail if the double uses decimal separator other than a decimal point // Added InvariantCulture option to ensure the current culture is ignored string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3} {4} {5}", dms.LatDegrees, dms.LatMinutes, dms.LatSeconds, dms.LonDegrees, dms.LonMinutes, dms.LonSeconds); cn.PutCoordsFromDD(newInput); return(CoordinateType.DMS); } } catch { /* Conversion Failed */ } try { cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeCENTER, input); return(CoordinateType.GARS); } catch { /* Conversion Failed */ } try { cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeLL, input); return(CoordinateType.GARS); } catch { /* Conversion Failed */ } CoordinateGARS gars; if (CoordinateGARS.TryParse(input, out gars)) { try { cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeCENTER, gars.ToString("", new CoordinateGARSFormatter())); return(CoordinateType.GARS); } catch { /* Conversion Failed */ } } try { cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_Automatic); return(CoordinateType.MGRS); } catch { /* Conversion Failed */ } try { cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_NewStyle); return(CoordinateType.MGRS); } catch { /* Conversion Failed */ } try { cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_NewWith180InZone01); return(CoordinateType.MGRS); } catch { /* Conversion Failed */ } try { cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_OldStyle); return(CoordinateType.MGRS); } catch { /* Conversion Failed */ } try { cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_OldWith180InZone01); return(CoordinateType.MGRS); } catch { /* Conversion Failed */ } // mgrs try parse CoordinateMGRS mgrs; if (CoordinateMGRS.TryParse(input, out mgrs)) { try { cn.PutCoordsFromMGRS(mgrs.ToString("", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_NewStyle); return(CoordinateType.MGRS); } catch { /* Conversion Failed */ } } try { cn.PutCoordsFromUSNG(input); return(CoordinateType.USNG); } catch { /* Conversion Failed */ } CoordinateUSNG usng; if (CoordinateUSNG.TryParse(input, out usng)) { try { cn.PutCoordsFromUSNG(usng.ToString("", new CoordinateMGRSFormatter())); return(CoordinateType.USNG); } catch { /* Conversion Failed */ } } try { cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMAddSpaces, input); return(CoordinateType.UTM); } catch { /* Conversion Failed */ } try { cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMNoOptions, input); return(CoordinateType.UTM); } catch { /* Conversion Failed */ } try { cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMUseNS, input); return(CoordinateType.UTM); } catch { /* Conversion Failed */ } CoordinateUTM utm; if (CoordinateUTM.TryParse(input, out utm)) { try { cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMNoOptions, utm.ToString("", new CoordinateUTMFormatter())); return(CoordinateType.UTM); } catch { /* Conversion Failed */ } } /* * Updated RegEx to capture invalid coordinates like 00, 45, or 456987. */ Regex regexMercator = new Regex(@"^(?<latitude>\-?\d+[.,]?\d*)[+,;:\s]{1,}(?<longitude>\-?\d+[.,]?\d*)"); var matchMercator = regexMercator.Match(input); if (matchMercator.Success && matchMercator.Length == input.Length) { try { var Lat = Double.Parse(matchMercator.Groups["latitude"].Value); var Lon = Double.Parse(matchMercator.Groups["longitude"].Value); IMap map = ((IMxDocument)ArcMap.Application.Document).FocusMap; var sr = map.SpatialReference != null ? map.SpatialReference : ArcMapHelpers.GetSR((int)esriSRProjCS3Type.esriSRProjCS_WGS1984WebMercatorMajorAuxSphere); point.X = Lon; point.Y = Lat; point.SpatialReference = sr; return(CoordinateType.DD); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } return(CoordinateType.Unknown); }
internal IPolygon GetMGRSPolygon(IPoint point) { CoordinateMGRS mgrs; IPointCollection pc = new RingClass(); // bottom left CoordinateMGRS.TryParse(InputCoordinate, out mgrs); if (mgrs == null) { return(null); } // don't create a polygon for 1m resolution if (mgrs.Easting.ToString().Length > 4 && mgrs.Northing.ToString().Length > 4) { return(null); } var tempPoint = (IConversionNotation) new PointClass(); ((IPoint)tempPoint).SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR(); var anotherMGRSstring = mgrs.ToString("", new CoordinateMGRSFormatter()); tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic); pc.AddPoint(tempPoint as IPoint); // top left var tempMGRS = new CoordinateMGRS(mgrs.GZD, mgrs.GS, mgrs.Easting, mgrs.Northing); var tempEasting = mgrs.Easting.ToString().PadRight(5, '0'); tempMGRS.Easting = Convert.ToInt32(tempEasting); var tempNorthing = mgrs.Northing.ToString().PadRight(5, '9'); tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9')); tempPoint = (IConversionNotation) new PointClass(); ((IPoint)tempPoint).SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR(); anotherMGRSstring = tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()); tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic); pc.AddPoint(tempPoint as IPoint); // top right tempEasting = mgrs.Easting.ToString().PadRight(5, '9'); tempMGRS.Easting = Convert.ToInt32(tempEasting.Replace('0', '9')); tempNorthing = mgrs.Northing.ToString().PadRight(5, '9'); tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9')); tempPoint = (IConversionNotation) new PointClass(); ((IPoint)tempPoint).SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR(); tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic); pc.AddPoint(tempPoint as IPoint); // bottom right tempEasting = mgrs.Easting.ToString().PadRight(5, '9'); tempMGRS.Easting = Convert.ToInt32(tempEasting.Replace('0', '9')); tempNorthing = mgrs.Northing.ToString().PadRight(5, '0'); tempMGRS.Northing = Convert.ToInt32(tempNorthing); tempPoint = (IConversionNotation) new PointClass(); (tempPoint as IPoint).SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR(); tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic); pc.AddPoint(tempPoint as IPoint); // create polygon var poly = new PolygonClass(); poly.SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR(); poly.AddPointCollection(pc); poly.Close(); return(poly); }
internal virtual void OnFlashPointCommand(object obj) { ProcessInput(InputCoordinate); Mediator.NotifyColleagues(CoordinateConversionLibrary.Constants.RequestOutputUpdate, null); IGeometry address = obj as IGeometry; if (address == null && amCoordGetter != null && amCoordGetter.Point != null) { address = amCoordGetter.Point; } if (address != null) { // Map und View IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument; IActiveView activeView = mxdoc.ActivatedView; IMap map = mxdoc.FocusMap; IEnvelope envelope = activeView.Extent; //ClearGraphicsContainer(map); IScreenDisplay screenDisplay = activeView.ScreenDisplay; short screenCache = Convert.ToInt16(esriScreenCache.esriNoScreenCache); ISpatialReference outgoingCoordSystem = map.SpatialReference; address.Project(outgoingCoordSystem); // is point within current extent // if so, pan to point var relationOp = envelope as IRelationalOperator; if (relationOp != null && activeView is IMap) { if (!relationOp.Contains(address)) { // pan to envelope.CenterAt(address as IPoint); activeView.Extent = envelope; activeView.Refresh(); } } IRgbColor color = new RgbColorClass(); color.Green = 80; color.Red = 22; color.Blue = 68; ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(); simpleMarkerSymbol.Color = color; simpleMarkerSymbol.Size = 15; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond; IElement element = null; IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = simpleMarkerSymbol; element = markerElement as IElement; IPolygon poly = null; if (InputCoordinateType == CoordinateType.MGRS || InputCoordinateType == CoordinateType.USNG) { poly = GetMGRSPolygon(address as IPoint); } if (poly != null) { address = poly; } var av = mxdoc.FocusMap as IActiveView; ArcMapHelpers.FlashGeometry(address, color, av.ScreenDisplay, 500, av.Extent); //AddElement(map, address); // do not center if in layout view //if (mxdoc.ActiveView is IMap) //{ // if (poly != null && !poly.IsEmpty && (poly as IArea) != null) // envelope.CenterAt((poly as IArea).Centroid); // else // envelope.CenterAt(amCoordGetter.Point); // activeView.Extent = envelope; // activeView.Refresh(); //} } }