Search code examples
pythongraphneo4jgislatitude-longitude

Is there a way to filter out latitude and longitude data that lies outside a specific region? Preferably using Python?


I want to display a set of nodes that are mapped to the region of Vancouver. However, the dataset that I build on contains nodes that are mapped to other regions such as Burnaby, Richmond, Surrey etc. My data is stored as a collection of csv files, and I want to filter the data parsing through the data so that only those nodes that contain latitude and longitude lying inside the region of Vancouver (marked by a yellow rectangle in the picture below - link specified) are displayed and the others are ignored. Any leads to this case will be much appreciated!

IMAGE LINK: https://ibb.co/Y8JhWJ4


Solution

  • I think you will want to apply something like this...

    import pandas as pd
    
    LATITUDE_KEY = 'Latitude'
    LONGITUDE_KEY = 'Longitude'
    columns = [ \
      # stuff and
      LATITUDE_KEY,
      LONGITUDE_KEY
    ]
    
    nodes = pd.read_csv('place_nodes.csv', names=columns)  
    nodes = nodes[nodes[LATITUDE_KEY].between(LAT_MIN, LAT_MAX) \
      & nodes[LONGITUDE_KEY].between(LONG_MIN, LONG_MAX)]