Create a layer from a CSV file using API for Python

1087
3
05-11-2021 05:57 AM
jiyeonseo1
New Contributor

Hi everyone,

I'm a newbie of ArcGiS API for Python. Now I'm getting stuck with how to create a layer that is a freeway network. I have a CSV file that contains the longitude and latitude of points. How can I create polylines and set up its color base on the data in the CSV file? 

Thank you so much!

0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

The built-in methods for converting a CSV to a feature layer are geared towards point features, not lines. To read a text-based file as a series of lines, you'll need to get those lat/lon pairs into a single string following a recognizable format like GEOJSON or WKT. Otherwise, there's no way for it to know, from a list of coordinates, where one line starts/stops, or what order to connect them in.

Where did you get the data, that it is in such a format? There are lots of easier ways ways of getting such things.

- Josh Carlson
Kendall County GIS
jiyeonseo1
New Contributor

Thank you for your kind help, Mr. Josh Carlson.

I got the CSV file from a survey of a highway route, which contains a number of features, including longitude and latitude.

My purpose is to create a layer of the route and add it to the base map. Can you explain the easier ways of getting such things?

Please find the enclosed file below for more details.

Thank you so much.

0 Kudos
jcarlson
MVP Esteemed Contributor

Often, things like highways will already have some authoritative source, like a national / state / local government entity. They may or may not make the data available, though.

However, my first choice for getting most data, especially highway data, is to look on OpenStreetMap. The highway you're working with is already in there, and you can query the Overpass API to get the linear features and export it to something like GEOJSON, which the ArcGIS Python API can interpret as a FeatureSet.

Once you have your line features, you can use the CSV as a points layer and snap the line to it, as your points are more precise. With aligned points and lines (or nodes and edges, in network dataset terms), you've got the basic framework for a network.

I should note, the ArcGIS Python API is meant to work with existing network datasets, but not create them. Creating a network dataset is a whole other process.

- Josh Carlson
Kendall County GIS
0 Kudos