Dynamic Point To X,Y

In this blog we learn about using a feature class as a table and bypassing the default geomoetry values to project point data from fields values. 

  • Jason Tromborg, Dallas Crow
  • ESRI tools
  • spatial reference
  • referenced data
  • feature service
  • Lat Long fields
  • point geometry
  • XY table
  • JavaScript
  • geodatabase
  • ArcGIS Enterprise
 

 

Display Lat Long Fields instead of Feature Geometry

Have you ever needed to publish a table as referenced data in ArcGIS Enterprise, only to find that it wasn't possible by default? When I was working on a project recently, I ran into the same problem. After looking into different ways to solve it, I found one that worked for me. In this blog post, I'll explain how I published a referenced feature layer as a table in ArcGIS Enterprise, step by step, and how I overcame the problems I ran into.

 

Getting Started:

The first problem I had was that I couldn't publish a table that was linked to my Enterprise Geodatabase in ArcGIS Enterprise. This was a big problem because I had to export from a system interface that has a Lat and Long field which I wanted to display in a custom JavaScript app. I also had to make sure that this data was displayed as dynamically as possible, with Lat Long Fields shown as point geometry, so that we could build link systems together.

After doing some research, I decided to publish an initial feature class by taking the SQL table export and using the "XY Table to Point" geoprocessing tool. Then I published the feature service as a referenced data feature to my organizations Enterprise Portal. Next Instated coding my JavaScript app. This is when things got a little cool.

function displayUpdatedGeometries(featureLayer, map) {
	featureLayer.renderer = myRenderer;
	featureLayer.queryFeatures({
		where: "1=1",
		outFields: ["*"],
		returnGeometry: true
	}).then(function (result) {
		var features = result.features;
		console.log(result)
		features.forEach(function (feature) {
			point = {
				type: "point",
				y: feature.attributes.GIS_LATITUDE,
				x: feature.attributes.GIS_LONGITUDE,
				spatialReference: {
					wkid: 4326
				},
				latitude: feature.attributes.GIS_LATITUDE,
				longitude: feature.attributes.GIS_LONGITUDE,
			};
		});
		newFeatureLayer = new FeatureLayer({
			geometry: point,
			source: features,
			objectIdField: "OBJECTID",
			fields: featureLayer.fields,
			geometryType: "point",
			spatialReference: {
				wkid: 4326
			},
			renderer: myRenderer,
			outFields: ["*"],
			featureReduction: clusterConfig
		});
		map.add(newFeatureLayer);
		featureLayer.refresh();
	}).catch(function (error) {
		console.log("Error querying features:", error);
	});

}
startingFeature = new FeatureLayer({
	url: app.myFeature,
	outFields: ["*"],
});
displayUpdatedGeometries(startingFeature, app.webmap);

 

Benefits:

I was able to dynamically plot an XY table in a geographic coordinate system by using this method, which was pretty easy. I linked tables to update the fields in the feature class but not the ESRI point geometry. This left the point geometry as a record of the last time the geometry was updated using arcpy. So now I could script an update that would take the XY field and overwrite the geometry and set it to a weekly basis.

I was also able to change the code to show a ghost image of the feature's point geometry to a on.hover event trigger. I even gave points a different color if their shape didn't match the latitude and longitude of the feature tables. This helped me keep track of changes and make sure everything was going well.

In the end, I created a method to let users see what has recently changed and where it changed from. This part of the code is not in production as it was just a test to see what could work but I find it very interesting to come up with unique ways to let users see their data.

var circleSymbol = {
	type: "simple-marker",
	color: "red",
	size: "10px",
	outline: {
		color: [255, 255, 255],
		width: 1
	}
};
var currentHoveredFeature = null;
app.mapView.on("pointer-move", function (event) {
	var point = event.mapPoint;
	app.mapView.whenLayerView(newFeatureLayer).then(function(layerView) {
		var query = layerView.layer.createQuery();
		query.geometry = point;
		layerView.queryFeatures(query).then(function (newFeatures) {
			var matchingIDs = newFeatures.features
				.map(function (newFeature) {
					return newFeature.attributes.ID;
				});
			if (startingFeature.features) {
				var oldFeatures = startingFeature.features
					.filter(function (oldFeature) {
						return matchingIDs.includes(oldFeature.attributes.ID);
					});
				if (currentHoveredFeature) {
					app.mapView.graphics.remove(currentHoveredFeature);
					currentHoveredFeature = null;
				}
				oldFeatures.forEach(function (oldFeature) {
					var matchingPoint = oldFeature.geometry;
					var graphic = new Graphic({
						geometry: matchingPoint,
						symbol: circleSymbol
					});
					app.mapView.graphics.add(graphic);
					currentHoveredFeature = graphic;
				});
			}
		});
	});
});

 

Wrapping it up:

It can be fun to find work-arounds to publishing a referenced table in ArcGIS Enterprise. But if you do some research and think outside the box, you can find a way out that works for you. After all, if you have not developed a work-around to get ESRI tools working for you are you really even trying :) Using the method I explained in this blog post, you can dynamically show Lat Long Fields as point geometry. I hope this blog post was helpful, and I encourage you to share your own solutions and ideas for publishing a referenced table in ArcGIS Enterprise.