Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)

Any suggestions on how to create a graphic point by xy value?

Thank You

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
I tried your code and still got the NullReference exception not set to an object reference error on point.setX(-100.0) line. Any ideas? –  artwork21 Jan 25 '12 at 16:21
    
@artwork21 I've reworked your code replacing your new Point() with new PointClass(). –  Stephen Quan Feb 2 '12 at 3:51

What API are you using...it 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)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.