1

I have implemented this code to create point event layer by xy text file.

However, I'm wondering how to create a point graphic by xy value?

  • This script draws point graphic by mouse down. When I steer away from the mouse down event and input my xy values manually it does not draw.

  • Using the Point class looks like it might also be a solution, however I'm not sure how to implement this code without getting a null reference error on point.setX line.

Dim point As New Point()
point.setX(-100.0) 
point.setY(40) 
Dim markerElement As New MarkerElement() 
markerElement.setGeometry(point)
 
Dim map As IMap = mxdoc.FocusMap
 
Map.addElement(markerElement, 0)
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 24, 2012 at 14:25
0

2 Answers 2

4

In the ArcGIS Resource Center is a discussion about Working with map elements which gives you an example on how to create a Point:

Dim point As IPoint = New PointClass()
point.X = 0
point.Y = 0

Then you can use the AddGraphicToMap snippet to draw the graphic on the map using the supplied colors.

answered Jan 25, 2012 at 4:05
0
2

The API you are using looks like a mix of VB.NET and JavaScript or according to one of your links. If you are using VB.NET turn on Option Explicit and Option Strict and I'd bet you get some errors.

The IPoint interface doesn't expose 'setX' in .NET. You need to call:

point.X = 0
point.Y = 0

The complete code would look like:

Dim map As ESRI.ArcGIS.Carto.IMap = mxdoc.FocusMap
Dim point As IPoint = New ESRI.ArcGIS.Geometry.Point()
point.SpatialReference = map.SpatialReference
point.X = -100
point.Y = 40
Dim rgbColor As ESRI.ArcGIS.Display.IRgbColor = New ESRI.ArcGIS.Display.RgbColor()
rgbColor.Blue = 200
AddGraphicToMap(map, point, rgbColor, rgbColor)
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Feb 1, 2012 at 23:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.