Search code examples
pythonarcgis

Generating geographical coordinates from giver corner


Based on the given corner in the map(position A), I want to generate more coordinates towards position B by adding some small values (distances) in the given latitude and longitude. For instance:

  • There are 6 houses from position A to B in a map. If I know the latitude, Longitude of 1 house ( 143.5689855, -38.328956999999996), how can I create the coordinates for the remaining 5?
  • I tried to achieve this by adding some small numbers in coordinates of a given corner as shown in below script. But the code only output for 1 house. How can I create a loop in my code that will automatically add the given small number and displays new coordinates for the rest of houses or even for bigger area?

enter image description here

What I have tried:

from arcgis.gis import GIS
from arcgis.geocoding import geocode
from arcgis.geocoding import reverse_geocode
import pprint

# Create an anonymous connection to ArcGIS Online
gis = GIS()


#45-Stodart-St (given corner)
geocode_home = geocode(address="45 Stodart St, Colac VIC 3250")
location = [geocode_home[0]["location"]['x'], geocode_home[0]["location"]['y']]
pprint.pprint(location)


#Add some small numbers in origanal location. This will give us coordinates of next house i.e 43-Stodart-St

#43-Stodart-St

new_loc = [location[0]+0.0002215*1,location[1]*0.999999]

pprint.pprint(new_loc)

Output:

enter image description here


Solution

  • Assuming you have the 2 locations of house A and house B as loc_A and loc_B. Assuming you know the house numbers of A and B. --> You know the number of houses.

    The following code will iterate over the house numbers and create a list of locations:

    longitude_diff = loc_B[0] - loc_A[0]
    latitude_diff = loc_B[1] - loc_A[1]
    house_locations = []
    
    for i in range(1, house_number_B - house_number_A):
        house_locations.append([loc_B[0] + i * longitude_diff/(house_number_B - house_number_A),
               loc_B[1] + i * latitude_diff/(house_number_B - house_number_A)])