New answers tagged

0

Heroku now has built-in, experimental support for a few geo-location libraries including shapely's dependency GEOS. You just need to set the following config variable from your command line: heroku config:set BUILD_WITH_GEO_LIBRARIES=1 You can find out more here


4

Why import geopandas if you don't use it ? (GeoPandas = Pandas + Fiona + Shapely) 1) Following the suggestion of bugmenot123 The schema for a MultiLineString schema = { 'geometry': 'MultiPoint', 'properties': {'id': 'int'}, } And with fiona.open("lines.shp") as inp: with fiona.open('result.shp', 'w', 'ESRI Shapefile', schema) as out: for ...


0

You are trying to save two Point objects into a schema that wants one Point. You could either use MultiPoint instead or construct a linestring for each start-end pair.


1

You have many solutions and I use here a simple example 1) the easiest way from shapely.geometry import Point, LineString line = LineString([(1,2),(2,4),(4,5)]) point = Point(2,4) First, you must determine if the point is within the line (Determine if shapely point is within a linestring/multilinestring) line.distance(point) < 1e-8 True print ...


0

For this to work you will have to first unary_union lines2.geometry so that lines1 will snap to any line in lines2. And as snap isn't a vectorized function you will have to execute for each geometry using apply: res = lines1 lines2_union = lines2.geometry.unary_union res.geometry = lines1.geometry.apply(lambda x: snap(x, lines2_union, 10))


0

I think I found an interim solution, which I'm posting in case it's useful for anyone: import pandas as pd import numpy as np from geopandas import GeoDataFrame from shapely.geometry import Point, LineString # Zip the coordinates into a point object and convert to a GeoDataFrame geometry = [Point(xy) for xy in zip(df.lon, df.lat)] df = GeoDataFrame(df, ...


0

It's possible PostGIS is doing something under the covers that you need to do by hand in Shapely. We use prepared geometry automatically in predicate loops, and in Shapely you might need to marshall that on purpose. Depends on what your process actually entails. Advantages of python are the lower install overhead and the library of potential other features ...


1

The quickest way is to keep the geometry in hex-encoded WKB. import psycopg2 from shapely import wkb conn = psycopg2.connect('...') curs = conn.cursor() shps = {} # key: gid, value: Shapely geom curs.execute('select gid, geom as geom from pysal.stl_hom;') for gid, geom in curs: shps[gid] = wkb.loads(geom, hex=True) There's no need to use GeoJSON, ...


0

Platform OS X 10.11 El whatever ,python 2.7.11 ,shapely 1.5.16 I had a similar problem when I import geo-related package inside python. from shapely.geometry import shape, MultiPolygon and I had such a thing Failed `CDLL(/usr/local/lib/libgeos_c.dylib)` I search a lot on Google. But for me, the problem just ends with doing ...


1

The easiest solution is to get a dictionary from query (psycopg2.extras: Real dictionary cursor or Dictionary-like cursor ) and the GeoJson format (ST_AsGeoJSON) import psycopg2 conn = psycopg2.connect("dbname='strati 'host='localhost' user='me'") import psycopg2.extras dict_cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) dict_cur.execute("...


0

Your script is too complex, simple use the modulo function def azimuth(point1, point2): '''azimuth between 2 shapely points (interval 0 - 360)''' angle = np.arctan2(point2.x - point1.x, point2.y - point1.y) return np.degrees(angle)if angle>0 else np.degrees(angle) + 360 azimuth(interP,P2) 112.61986494834154 azimuth(P2,interP) 292....


1

In order to calculate the angle P1-InterPoint-P2: Calculate the difference of the azimuths InterPoint-P1 and Interpoint-P2. Mind you that you have to investigate the azimuth according to the quadrant that it lies, so: if dx>0 & dy>0 : final azimith=azimuth if dx<0 & dy>0 : final azimuth=180-azimuth if dx<0 & dy<0: final ...



Top 50 recent answers are included