2

I have 2 csv files both with 3 columns: variable, lat, lon.

Let's call them file A and file B. File A has 100 values for variable (in this case city), File B has 100,000 values for variable (station numbers in this case).

The goal is to assign a city (from file A) to every station number (from file B). So for each city, I will have a station number which is the closest station number to that city (by euclidian distance using latitude longitude).

Does anyone know how I can do this? I've looked at using Nearest but that doesn't seem like what I'm looking for.

I can use ArcPy also if that helps, but I'm not too experienced in ArcGIS.

  • 1
    What GIS software and version would you prefer to use to do this? Please edit this detail into your Question. At the moment it sounds like ArcGIS/ArcPy is your second choice software. – PolyGeo Jan 9 '14 at 1:05
  • 1
    Some will know what you mean by "...using Nearest" but what is the context (name of package)? – Martin F Jan 9 '14 at 1:10
  • 1
    also it is rarely recommended to compute an euclidian distance in lat/long due to distortions. – radouxju Jan 9 '14 at 6:48
4

You could use a spatial join, which will give each point in file B the attributes of the nearest point in file A, as well as creating a new field that gives the distance between the points.

Edit: This suggestion is assuming an arcgis platform, and assuming from the text that you have generated a spatial layer from the two files. the spatial join can be run by right-clicking on the target layer (file B) going to joins and relates/join... and selecting "Join data from another layer based on spatial location" in the first drop down, selecting file A from the second menu, and clicking the "Each point will be given the attributes of the point closeest to it..." radio button. this will create a new layer

  • Doesn't this assume that a certain package is being used? Is the answer detailed enough? – Martin F Jan 9 '14 at 1:12
  • 2
    I inferred from the reference to Nearest and ArcPy that it's some version of ArcGIS 10, though the spatial join would apply to older Arc versions as well. – TDavis Jan 9 '14 at 1:46
2

Have you considered the Near tool? This would be useful if the csv files were converted to point shapefiles. Once this is done, you set the input feature to city points and the near features to the station points. This will assign the object id of the nearest station point to each city point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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