Distance between coordinates

1

I'm trying to calculate the distance between coordinates, the data to be compared comes from an sql query and a geojson.

The query data are points that correspond to properties while the json data are vias.

I need to take the first point and calculate the distance to the nearest road, so on with all the points of the query within a radius of 20 KM, if you do not find anything in that radius the exit is' There are no roads nearby '.

I managed to get to read the data of the query and I am stopped when reading the json and calculate the distances in that radius.

import geopandas as geo
import pyodbc

cnn = pyodbc.connect('Driver={SQL Server};Server=****;Database=****;uid=****;pwd=****')

sqlcmd = ("Select lng, lat from inmuebles \
           inner join InmuebleDivisionPolitica b on a.idInmueble = b.idInmueble \
           inner join DivisionPolitica c on c.idDivisionPolitica = b.idDivisionPolitica \
           inner join Direccion d on d.idDivisionPolitica = c.idDivisionPolitica where d.geom is not null")

cursorConsulta = cnn.cursor()
cursorConsulta.execute(sqlcmd)

sh = geo.read_file('C:\Ferrocariles\ViasServicioPasajerosActivos.shp')

with open('C:\Ferrocariles\ViasServicioPasajerosActivos.geojson', 'w') as f:
    f.write(sh.to_json())

for r in cursorConsulta:

    latOrigen = str(r[1])
    lngOrigen = str(r[0])

the geojson data by way of example are the following

{
    "type": "FeatureCollection",
    "features": [
        {
            "id": "0",
            "type": "Feature",
            "properties": {
                "Name": "L�nea G - Buenos Aires - Tapiales",
                "LINEA": "BELGRANO",
                "RAMAL": "G",
                "KM": 16.62,
                "ACTIVA": "SI",
                "CABECERAS": "Buenos Aires - González Catán",
                "SERVICIO": "Trenes urbanos en el AMBA",
                "CONCESION": " (Estatal, Nación)",
                "OBSERVAC": ""
            },
            "geometry": {
                "type": "LineString",
                "coordinates": [
                    [
                        -58.39323087479187,
                        -34.64522852285068
                    ],
                    [
                        -58.39493519860744,
                        -34.64593911202303
                    ],
                    [
                        -58.39540370387294,
                        -34.64612018963881
                    ],
                    [
                        -58.39577715270643,
                        -34.64624297063709
                    ],
                    [
                        -58.3961720086682,
                        -34.64636735300267
                    ],
                    [
                        -58.39657393244798,
                        -34.64649079664271
                    ],
                ]
            }
        },
        {
            "id": "1",
            "type": "Feature",
            "properties": {
                "Name": "L�nea G: Tapiales - Gonzalez Catan",
                "LINEA": "BELGRANO",
                "RAMAL": "G",
                "KM": 18.47,
                "ACTIVA": "SI",
                "CABECERAS": "Buenos Aires - González Catán",
                "SERVICIO": "Trenes urbanos en el AMBA",
                "CONCESION": " (Estatal, Nación)",
                "OBSERVAC": ""
            },
            "geometry": {
                "type": "LineString",
                "coordinates": [
                    [
                        -58.51164133538381,
                        -34.70237187907585
                    ],
                    [
                        -58.50886122230304,
                        -34.70446888060354
                    ],
                    [
                        -58.50807265291671,
                        -34.70505643669129
                    ],
                    [
                        -58.5075876903448,
                        -34.70536763434288
                    ],
                    [
                        -58.50672881971201,
                        -34.70591466418704
                    ],
                    [
                        -58.50612050168868,
                        -34.70630557185193
                    ],
                    [
                        -58.50586890953366,
                        -34.70652771805103
                    ],
                    [
                        -58.50574833497523,
                        -34.70665678170097
                    ],
                    [
                        -58.50557625423573,
                        -34.70683067509435
                    ],
                    [
                        -58.50545796343254,
                        -34.70698015127397
                    ],

                ]
            }
        }
    
asked by Sebastian 21.02.2018 в 12:41
source

0 answers