Shapely

您所在的位置:网站首页 shapely安装 Shapely

Shapely

2024-07-10 07:37| 来源: 网络整理| 查看: 265

Shapely# Documentation Status Travis CI status PyPI Anaconda

Manipulation and analysis of geometric objects in the Cartesian plane.

https://c2.staticflickr.com/6/5560/31301790086_b3472ea4e9_c.jpg

Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It is using the widely deployed open-source geometry library GEOS (the engine of PostGIS, and a port of JTS). Shapely wraps GEOS geometries and operations to provide both a feature rich Geometry interface for singular (scalar) geometries and higher-performance NumPy ufuncs for operations using arrays of geometries. Shapely is not primarily focused on data serialization formats or coordinate systems, but can be readily integrated with packages that are.

What is a ufunc?#

A universal function (or ufunc for short) is a function that operates on n-dimensional arrays on an element-by-element fashion and supports array broadcasting. The underlying for loops are implemented in C to reduce the overhead of the Python interpreter.

Multithreading#

Shapely functions generally support multithreading by releasing the Global Interpreter Lock (GIL) during execution. Normally in Python, the GIL prevents multiple threads from computing at the same time. Shapely functions internally release this constraint so that the heavy lifting done by GEOS can be done in parallel, from a single Python process.

Usage#

Here is the canonical example of building an approximately circular patch by buffering a point, using the scalar Geometry interface:

>>> from shapely import Point >>> patch = Point(0.0, 0.0).buffer(10.0) >>> patch >>> patch.area 313.6548490545941

Using the vectorized ufunc interface (instead of using a manual for loop), compare an array of points with a polygon:

>>> import shapely >>> import numpy as np >>> geoms = np.array([Point(0, 0), Point(1, 1), Point(2, 2)]) >>> polygon = shapely.box(0, 0, 2, 2) >>> shapely.contains(polygon, geoms) array([False, True, False])

See the documentation for more examples and guidance: https://shapely.readthedocs.io

Requirements#

Shapely 2.0 requires

Python >=3.7

GEOS >=3.5

NumPy >=1.14

Installing Shapely#

We recommend installing Shapely using one of the available built distributions, for example using pip or conda:

$ pip install shapely # or using conda $ conda install shapely --channel conda-forge

See the installation documentation for more details and advanced installation instructions.

Integration#

Shapely does not read or write data files, but it can serialize and deserialize using several well known formats and protocols. The shapely.wkb and shapely.wkt modules provide dumpers and loaders inspired by Python’s pickle module.

>>> from shapely.wkt import dumps, loads >>> dumps(loads('POINT (0 0)')) 'POINT (0.0000000000000000 0.0000000000000000)'

Shapely can also integrate with other Python GIS packages using GeoJSON-like dicts.

>>> import json >>> from shapely.geometry import mapping, shape >>> s = shape(json.loads('{"type": "Point", "coordinates": [0.0, 0.0]}')) >>> s >>> print(json.dumps(mapping(s))) {"type": "Point", "coordinates": [0.0, 0.0]} Support#

Questions about using Shapely may be asked on the GIS StackExchange using the “shapely” tag.

Bugs may be reported at shapely/shapely#issues.

Copyright & License#

Shapely is licensed under BSD 3-Clause license. GEOS is available under the terms of GNU Lesser General Public License (LGPL) 2.1 at https://libgeos.org.

Credits#

Shapely is written by:

Adi Shavit

Alan D. Snow

Alberto Rubiales

Allan Adair

Andrew Blakey

Andy Freeland

Ariel Kadouri

Aron Bierbaum

Bart Broere

Bas Couwenberg

Ben Beasley

Benjamin Root

BertrandGervais

Bhavika Tekwani

Bi0T1N

Brad Hards

Brendan Ward

Brandon Wood

Casper van der Wel

Chad Hawkins

Christian Prior

Christian Quest

Christophe Pradal

Dan Baston

Dan Mahr

Daniele Esposti

Dave Collins

David Baumgold

David Swinkels

Denis Rykov

Enrico Ferreguti

Erwin Sterrenburg

Ewout ter Hoeven

Felix Divo

Felix Yan

Filipe Fernandes

Frédéric Junod

Gabi Davar

Gerrit Holl

Hannes

Hao Zheng

Henry Walshaw

Howard Butler

Hugo

Idan Miara

Jacob Wasserman

Jaeha Lee

James Douglass

James Gaboardi

James Lamb

James McBride

James Spencer

Jamie Hall

Jason Sanford

Jeethu Rao

Jeremiah England

Jinkun Wang

Johan Euphrosine

Johannes Schönberger

Jonathan Schoonhoven

Joris Van den Bossche

Joshua Arnott

Juan Luis Cano Rodríguez

Justin Shenk

Kai Lautaportti

Kelsey Jordahl

Kevin Wurster

Konstantin Veretennicov

Koshy Thomas

Krishna Chaitanya

Kristian Evers

Kyle Barron

Leandro Lima

Lukasz

Luke Lee

Maarten Vermeyen

Marc Jansen

Marco De Nadai

Martin Fleischmann

Mathieu

Matt Amos

Matthias Cuntz

MejstrikRudolf

Michael K

Michel Blancard

Mike Taves

Morris Tweed

Naveen Michaud-Agrawal

Oliver Tonnhofer

Paveł Tyślacki

Peter Sagerson

Phil Elson

Pierre PACI

Raja Gangopadhya

Ricardo Zilleruelo

Rémy Phelipot

S Murthy

Sampo Syrjanen

Samuel Chin

Sean Gillies

Sobolev Nikita

Stephan Hügel

Steve M. Kim

Taro Matsuzawa aka. btm

Thibault Deutsch

Thomas Gratier

Thomas Kluyver

Tim Gates

Tobias Sauerwein

Tom Caruso

Tom Clancy

WANG Aiyong

Will May

Zachary Ware

aharfoot

bstadlbauer

cclauss

clefrks

davidh-ssec

georgeouzou

giumas

gpapadok

joelostblom

ljwolf

mindw

rsmb

shongololo

solarjoe

sshuair

stephenworsley

See also: shapely/shapely.

Additional help from:

Justin Bronn (GeoDjango) for ctypes inspiration

Martin Davis (JTS)

Sandro Santilli, Mateusz Loskot, Paul Ramsey, et al (GEOS Project)

Major portions of this work were supported by a grant (for Pleiades) from the U.S. National Endowment for the Humanities (https://www.neh.gov).

Frequently asked questions and answers# I installed shapely in a conda environment using pip. Why doesn’t it work?#

Shapely versions < 2.0 load a GEOS shared library using ctypes. It’s not uncommon for users to have multiple copies of GEOS libs on their system. Loading the correct one is complicated and shapely has a number of platform-dependent GEOS library loading bugs. The project has particularly poor support for finding the correct GEOS library for a shapely package installed from PyPI into a conda environment. We recommend that conda users always get shapely from conda-forge.

Are there references for the algorithms used by shapely?#

Generally speaking, shapely’s predicates and operations are derived from methods of the same name from GEOS and the JTS Topology Suite. See the JTS FAQ for references describing the JTS algorithms.

I used .buffer() on a geometry with Z coordinates. Where did the Z coordinates go?#

The buffer algorithm in GEOS is purely two-dimensional and discards any Z coordinates. This is generally the case for the GEOS algorithms.

Indices and tables#

Index

Module Index

Search Page



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3