基本的なプログラミングのpython:pythonの格好の良い詳細なガイド

この記事は、格好の良いガイドを詳細パイソンを説明し、参照することができ困っている友達
格好の良いは、デカルト座標システムの幾何オブジェクトの操作および分析のためのPythonライブラリです。

パッケージの導入

from shapely.geometry import Point
 
from shapely.geometry import LineString

変数とメソッドがあります。

object.area

  Returns the area (float) of the object.

object.bounds

  返回对象的(minx,miny,maxx,maxy)元组(float类型)

object.length

  返回对象的长度

object.geom_type

  返回对象类型

object.distance(other)

  返回本对象和另一个对象的距离

object.representative_point()

  Returns a cheaply computed point that is guaranteed to be within the geometric object.
object.area

  Returns the area (float) of the object.

object.bounds

  返回对象的(minx,miny,maxx,maxy)元组(float类型)

object.length

  返回对象的长度

object.geom_type

  返回对象类型

object.distance(other)

  返回本对象和另一个对象的距离

object.representative_point()

  Returns a cheaply computed point that is guaranteed to be within the geometric object.
>>> from shapely.geometry import Point
>>> print Point(0,0).distance(Point(0,1))
1.0
>>> from shapely.geometry import LineString
>>> line = LineString([(0,0), (1,1), (1,2)])
>>> line.area
0.0
>>> line.bounds
(0.0, 0.0, 1.0, 2.0)
>>> line.length
2.414213562373095
>>> line.geom_type
'LineString'

ポイント

クラスポイント(座標)

割り当てモードの三種類

>>> point = Point(0,0)
>>> point_2 = Point((0,0))
>>> point_3 = Point(point)

0のポイント対象領域と長さを持っています

>>> point.area
0.0
>>> point.length
0.0

またはCOORDS座標X、Y、Zによって得ることができます

>>> p = Point(2,3)
>>> p.coords
<shapely.coords.CoordinateSequence object at 0x7ffbc3d60dd0>
 
>>> list(p.coords)
[(2.0, 3.0)]
>>> p.x
2.0
>>> p.y
3.0

COORDSはスライスすることができます

>>> p.coords[:]
[(2.0, 3.0)]

ラインストリング

ラインストリングのコンストラクタパラメータは、2点以上のシーケンスを渡され、

対象領域がゼロである折れ線、非ゼロ長

>>> line = LineString([(0,0), (0,1), (1,2)])
>>> line.area
0.0
>>> line.length
2.414213562373095

座標を取得します

>>> line.coords[:]
[(0.0, 0.0), (0.0, 1.0), (1.0, 2.0)]
 >>> list(line.coords)
 [(0.0, 0.0), (0.0, 1.0), (1.0, 2.0)]

ラインストリングは、まだオブジェクトの異なるタイプを受け入れることができます

>>> line2 = LineString(line)
>>> line2.coords[:]
[(0.0, 0.0), (0.0, 1.0), (1.0, 2.0)]

共通のフォーマット変換

>>> Point(1,1).wkt
'POINT (1 1)'
>>> Point(1,1).wkb
'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?'
>>> Point(1,1).wkb.encode('hex')
'0101000000000000000000f03f000000000000f03f'
>>> 
>>> Point(1,1).wkb.encode('hex')
'0101000000000000000000f03f000000000000f03f'

両方の負荷およびダンプ方法

WKTのための

>>> from shapely.wkt import dumps, loads
>>> s = dumps(Point(1,2))
>>> s
'POINT (1.0000000000000000 2.0000000000000000)'
>>> ss = loads(s)
>>> ss
<shapely.geometry.point.Point object at 0x7ffbc3d783d0>
>>> ss.coords[:]
[(1.0, 2.0)]

WKBのために

>>> from shapely.wkb import dumps, loads
>>> s = dumps(Point(1,2), hex=True)
>>> s
'0101000000000000000000F03F0000000000000040'
>>> ss = loads(s, hex=True)
>>> ss
<shapely.geometry.point.Point object at 0x7ffbc3d78790>
>>> ss.coords
<shapely.coords.CoordinateSequence object at 0x7ffbc3d783d0>
>>> ss.coords[:]
[(1.0, 2.0)]

、そして最終的に公共機関[プログラマ]の数では良い評判をお勧めする方法多くのより多くのコンテンツ、古いタイマー、スキルを学習体験、インタビューのスキル、職場体験や他のシェアを学習がたくさんある、より多くの我々は慎重に準備ゼロベース毎日、実際のプロジェクトデータの入門情報は、Pythonプログラマの技術のタイミングを説明、および方法は、細部に注意を払う必要があるいくつかの学習を共有しますここに画像を挿入説明

公開された35元の記事 ウォンの賞賛1 ビュー10000 +

おすすめ

転載: blog.csdn.net/chengxun02/article/details/105029605