Select to view content in your preferred language

Create Point from XY

3618
7
03-11-2021 06:40 AM
RobDunfey
Regular Contributor

How can I create a point from two projected coordinates?  I want to take two strings as input (X and Y) and then create a geometry at that point, re-project to WGS84 and add the result to the map?  The reason I am doing this is to publish as a GP service to consume in an AWAB application via the GP widget. Sounds easy, but stuck at creating the point! Any pointers appreciated 🙂

0 Kudos
7 Replies
DanPatterson
MVP Esteemed Contributor

XY Table To Point (Data Management)—ArcGIS Pro | Documentation

Make XY Event Layer (Data Management)—ArcGIS Pro | Documentation

you can even use Excel To Table

You need to define the coordinate system of your points first, then if you need another coordinate system, you can use the Project tool to produce a featureclass in the desired coordinates


... sort of retired...
RobDunfey
Regular Contributor

Hi Dan, I see that but it requires a table as input?  I want to publish two strings as parameters so the user is prompted for the X and Y, otherwise they have to create a table in something like excel?

Congrats on your retirement and thanks for taking the time to help.

Rob

0 Kudos
DanPatterson
MVP Esteemed Contributor

Thanks Rob.

A table as input is the easiest, especially since the coordinate system has to be dealt with and reprojecting to another.  No one is going to know the location of a point in Web Mercator coordinates. 

It seems that you want a degree of interactivity that doesn't fall within the "geoprocessing" category but more web app based.


... sort of retired...
0 Kudos
RobDunfey
Regular Contributor

So I've got this far, but a broken link when the result is added to the display in ArcGIS Pro...

import arcpy

long = arcpy.GetParameterAsText(0)
lat = arcpy.GetParameterAsText(1)

point = arcpy.Point(float(long), float(lat))
loc = arcpy.PointGeometry(point)


locfeatures = r"memory\locfeatures"

arcpy.MakeFeatureLayer_management(loc, locfeatures)
arcpy.SetParameter(2, locfeatures)

0 Kudos
DanPatterson
MVP Esteemed Contributor

Not sure what you mean but... from

Make Feature Layer (Data Management)—ArcGIS Pro | Documentation

The temporary feature layer can be saved as a layer file using the Save To Layer File tool or can be saved as a new feature class using the Copy Features tool.

It has to go somewhere (eg into a gdb) 


... sort of retired...
0 Kudos
RobDunfey
Regular Contributor

Hi Dan, I found one of your previous posts on another thread which fixed my GP issue last night.  The trick was to run copy features before running MakeFeatureLayer, so thanks for that.  I've attached a word document which explains what I'm doing.  I now have an issue with the AWAB GP tool so will head over there and see if I can find an answer.  Appreciate your help, Thanks, Rob.

0 Kudos
JyotiRohodia
Occasional Contributor

This works for me:

in_X = arcpy.GetParameterAsText(0)
in_Y = arcpy.GetParameterAsText(1)

point = arcpy.Point(in_X,in_Y)
sr = arcpy.SpatialReference("WGS 1984")
pointGeometry = arcpy.PointGeometry(point,sr)

0 Kudos