Skip to main content

主要模块包括: Messenger - 信使消息事件订阅与发布类; MapGisProject - MapGis工程文件(MPJ)读取类; MapGisColorLib - MapGis色库(青品黄黑-红绿蓝)读取类; MapGisFile - MapGis点线面文件读取类; Projection - 几何要素坐标投影变换类; MapGrid - 国际标准比例尺图幅分幅网格与编号类;Geometry - 地学几何要素加载、编码、转换与序列化类

Project description

GiserPy 2025.9.10
The fundamental package for GIS data processing with Python

GiserPy 软件包提供的模块如下:

  • Geometry - 地学几何要素加载、编码、转换与序列化类
  • Projection - 几何要素坐标投影变换类(支持高斯-克吕格、球体墨卡托、阿尔勃斯、兰伯特投影正反算)
  • MapGrid - 国际标准比例尺图幅分幅网格与编号类
  • MapGisProject - MapGis工程文件(MPJ)读取类
  • MapGisColorLib - MapGis色库(青品黄黑-红绿蓝)读取类
  • MapGisFile - MapGis点线面文件读取类
  • Messenger - 信使消息事件订阅与发布类(通常用于实时进度异步跟踪场景)

Installation

Install GiserPy project with pip

Windows

  python -m pip install --upgrade giserpy 

Linux

  python3 -m pip install --upgrade giserpy

MacOS

  python3 -m pip install --upgrade giserpy

Usage/Examples

>>> import giserpy as giser  # import geosite.giserpy as giser
>>> # 第一步:依据授权码进行模块注册
>>> giser.GiserBase().register('需联系研发团队并申请授权码')
>>> # 第二步:实例化工程文件对象
>>> mpj = giser.MapGisProject('d:\\J46E001002.MPJ')
>>> # 第三步:获取工程文件描述字典以及文件描述列表
>>> print(mpj.Description)
>>> print(mpj.Files)

API Reference

Get help on module GiserPy

>>> help(giserpy)
  • class Messenger(builtins.object)

    信使消息事件订阅与发布类(通常用于实时进度异步跟踪场景)
  • 用法
>>> # 第一步:在循环体外部创建一个消息总线实例
>>> msg = giser.Messenger()
>>> # 第二步:在循环体外部定义一个消息侦听句柄(插槽)函数,其参数<data>将由【publish】函数传递
>>> def messageSlot(data):
>>>     print('Received message:', data)
>>> # 第三步:在循环体外部订阅一条消息,比如:'progress' 消息并设置侦听句柄函数 messageSlot。注:仅当订阅(侦听)的消息名称与发布的消息名称一致时方可执行侦听句柄函数
>>> msg.subscribe('progress', messageSlot)
>>> # 第四步:在循环体内部发布若干条消息,比如:'progress' 消息并携带内容:'Hello, World!'。注:如果发布的消息名称无订阅者,便不执行任何操作
>>> msg.publish('progress', 'Hello, World!')

Messenger()

初始化函数,自动创建消息订阅者字典,其中,【键名】为消息名称或类别,【键值】为消息插槽函数列表(也就是说,一条消息可指定若干个侦听函数)

Messenger.subscribe

def subscribe(
       self,
       key: str,
       slot: Callable
) -> None

订阅特定消息键名及待回调的消息插槽函数。如果消息键名未曾订阅便创建与之绑定的空白列表,如果消息插槽函数尚不存在就将其追加到绑定函数列表中。如果键名和槽函数均已存在,将不执行任何操作

Parameter Type Description
key str 必选项,消息键名
slot Callable 必选项,消息插槽(回调)函数

失败时抛出异常

Messenger.unsubscribe

def unsubscribe(
        self, key: Union[str, None] = None, slot: Union[Callable, None] = None
) -> None

取消订阅的特定消息键名及回调的消息插槽函数。如果键名为空,就清空整个消息订阅者字典;如果槽函数为空,就删除与键名绑定的列表

Parameter Type Description
key Union[str, None] 可选项,消息键名
slot Union[Callable, None] 可选项,消息插槽(回调)函数

失败时抛出异常

Messenger.publish

def publish(
       self, key: str = None, value: Any = None
) -> None

向消息订阅者发布特定的消息(依据指定的键名遍历调用绑定列表中的所有插槽函数)。注:本函数以静默方式广播消息并遍历执行绑定的插槽函数,即使键名不存在或者消息插槽函数调用失败也不抛出异常

Parameter Type Description
key str 消息键名
value Any 消息内容,可为字符串、列表、字典、元组等类型。注:此类型应与侦听函数所需的参数类型一致

无返回值,以静默方式广播消息并不抛出异常


  • class MapGisColorLib(GiserBase)

    MapGis色库(青品黄黑-红绿蓝)读取类

MapGisColorLib(mapGisColorLib: str = None)

初始化构造函数。如果未指定色库文件名,便优先尝试读取当前文件夹内的【MapGIS/Slib/Pcolor.lib】,然后尝试读取模块嵌入的默认色库文件,如果前述的色库文件不存在或不符合文件基本要求,实例成员【PcolorLibFile】将置为None,实例成员【count】将置为0

Parameter Type Description
mapGisColorLib str 色库文件名,省略时取默认值:None

MapGisColorLib.CMYK

def CMYK(
       self, index: int = 1, defaultColor: tuple = (0, 0, 0, 100)
) -> tuple | None

依据颜色号从系统库中提取(青品黄黑)颜色值,每个颜色值百分比值域为[0,100]

Parameter Type Description
index int MapGIS色库颜色号(从1开始计数),注:如果色号越界,取默认颜色参数[defaultColor]设置值
defaultColor tuple 默认颜色,省略时取默认值:(0, 0, 0, 100)

返回(青,品,黄,黑)四元组

MapGisColorLib.RGB

def RGB(
       self, index: int = 1, defaultColor: tuple = (0, 0, 0)
) -> tuple | None

依据颜色号从系统库中提取(红绿蓝)颜色值,每个颜色值的值域为[0,255]

Parameter Type Description
index int MapGIS色库颜色号(从1开始计数),注:如果色号越界,取默认颜色参数[defaultColor]设置值
defaultColor tuple 默认颜色,省略时取默认值:(0, 0, 0)

返回(红,绿,蓝)三元组

  • 示例
>>> # 第一步:实例化对象
>>> colorLib = giser.MapGisColorLib()
>>> # 第二步:获取颜色库中全部色值
>>> for i in range(colorLib.count):
>>>     # MapGIS色库颜色号是从1开始计数的,因此需要:i + 1
>>>     index = i + 1
>>>     R, G, B = colorLib.RGB(index)
>>>     print(f'\033[38;2;{R};{G};{B}m' + '█' + '\033[0m', end='\n' if index % 30 == 0 else '')

MapGisColorLib.HEX

def HEX(
       self, index: int = 1, defaultColor: str = '#000000'
) -> str | None

依据颜色号从系统库中提取符合HTML格式的十六进制红绿蓝颜色字符串

Parameter Type Description
index int MapGIS色库颜色号(从1开始计数),注:如果色号越界,取默认颜色参数[defaultColor]设置值
defaultColor str 默认颜色,省略时取默认值:'#000000'

返回十六进制红绿蓝字符串(形如:#DEDF06)


  • class MapGisProject(GiserBase)

    MapGis工程文件(MPJ)读取类

MapGisProject(file: str, encoding: str = 'GB2312')

初始化构造函数。依据[file]参数初始化实例公有属性成员(description、files),其中,files成员中的'type'属性目前提供了['Point', 'LineString', 'Polygon', 'Unknown']四种分类;'statusCode'属性为文件状态码,分别为: 0=关闭态、1=打开态、2=编辑态、3=当前编辑态

Parameter Type Description
file str 文件名(MapGIS工程文件名称)
encoding str 语系编码,省略时取默认值:'GB2312'
  • 示例
>>> # 第一步:实例化对象
>>> mpj = giser.MapGisProject('.\\Data\\J46E001002.MPJ')
>>> # 第二步:获取工程描述字典以及文件描述列表
>>> print(mpj.Description)
>>> # {'identification': 'WMAP`D2:', 'typeCode': 9, 'files': 3, 'title': '', 'environment': '', 'layoutWidth': 34.0633385378964, 'layoutHeight': 21.9611292941757, 'layoutRotate': 0.0, 'layoutXoffset': -79.92002328, 'layoutYoffset': -26.92153596, 'layoutXscale': 1.0, 'layoutYscale': 1.0, 'xMin': 84.92002328, 'yMin': 31.92153596, 'xMax': 108.98336181789637, 'yMax': 44.48234101514034, 'sourceFile': 'D:\\Data\\J46E001002.MPJ'}
>>> print(mpj.Files) 
>>> # [{'type': 'Polygon', 'statusCode': 1, 'file': '.\\WP.WP', 'description': '', 'xmin': 99.62185619, 'ymin': 36.5514238, 'xmax': 100.75856675, 'ymax': 37.23177728, 'userType': 0, 'groupCode': 0, 'netWorkData': '', 'scaleMin': 0.0, 'scaleMax': 0.0, 'labelFlag': 0, 'labelFields': '', 'labelHeight': 0.0, 'labelColor': 0, 'labelFont': 0, 'legendType': 0}, {'type': 'LineString', 'statusCode': 1, 'file': '.\\WL.WL', 'description': '', 'xmin': 84.92002328, 'ymin': 31.92153596, 'xmax': 85.67607585, 'ymax': 32.39622771, 'userType': 0, 'groupCode': 0, 'netWorkData': '', 'scaleMin': 0.0, 'scaleMax': 0.0, 'labelFlag': 0, 'labelFields': '', 'labelHeight': 0.0, 'labelColor': 0, 'labelFont': 0, 'legendType': 0}, {'type': 'Point', 'statusCode': 1, 'file': '.\\WT.WT', 'description': '', 'xmin': 87.48651733249426, 'ymin': 34.16569747775793, 'xmax': 108.98336181789637, 'ymax': 44.48234101514034, 'userType': 0, 'groupCode': 0, 'netWorkData': '', 'scaleMin': 0.0, 'scaleMax': 0.0, 'labelFlag': 0, 'labelFields': '', 'labelHeight': 0.0, 'labelColor': 0, 'labelFont': 0, 'legendType': 0}]

  • class MapGisFile(GiserBase)

    MapGis点线面文件读取类

MapGisFile(mapGisFile: str, mapGisColorLib: str = None, encoding: str = 'GB2312')

初始化构造函数。依据指定的点线面图形文件初始化实例公有属性成员(TimeStamp、BBox、EPSG、Parameters、FileType、RecordCount、FeatureCount、FieldStruct)。失败时抛出异常。其中,FileType为图形文件类型(Point/LineString/Polygon)三者之一;EPSG为投影编号(0=自由坐标系;4326=地理坐标系;9802=兰伯特等角割圆锥;9822=阿尔勃斯等积割圆锥;9804=墨卡托正轴等角圆柱;4214=高斯-克吕格[北京坐标系];4610=高斯-克吕格[西安坐标系];其他=自定义坐标系);RecordCount为点线面记录总数(含已删除的记录);FeatureCount为点线面要素有效个数(不含已删除的要素)

Parameter Type Description
mapGisFile str MapGIS点线面图形文件名(wt、wl、wp),省略时取默认值:None
mapGisColorLib str MapGIS颜色库文件名(含路径),省略时取默认值:None。如果未指定色库文件名,便尝试读取当前文件夹内的【MapGis/Slib/Pcolor.lib】
encoding str 语系编码,省略时取默认值:'GB2312'

MapGisFile.describeProperty

def describeProperty(
       self
) -> Union[list, None]

获取 MapGIS 点线面图形文件的属性字段结构列表。注1:属性字段结构字典中字段列表的每个字段至少包括:name(字段名称)、type(字段类型)、length(字段长度),浮点类型额外包括:decimal(小数位);注2:返回结果取自实例属性[FieldStruct]中的[fields]内容

返回由属性字段结构字典构成的列表,无效时返回None,失败时抛出异常

  • 示例
>>> # 创建实例:
>>> mapgis = giser.MapGisFile('.\\Data\\WP.WP')
>>> print(mapgis.describeProperty())
>>> # [{'name': 'ID', 'type': 'long', 'typeCode': 3, 'size': 4, 'length': 8}, {'name': '面积', 'type': 'double', 'typeCode': 5, 'size': 8, 'length': 15, 'decimal': 6}, {'name': '周长', 'type': 'double', 'typeCode': 5, 'size': 8, 'length': 15, 'decimal': 6}, {'name': 'OBJECTID', 'type': 'long', 'typeCode': 3, 'size': 4, 'length': 20}, {'name': 'GB', 'type': 'long', 'typeCode': 3, 'size': 4, 'length': 20}, {'name': 'HYDC', 'type': 'string', 'typeCode': 0, 'size': 255, 'length': 254}, {'name': 'NAME', 'type': 'string', 'typeCode': 0, 'size': 255, 'length': 254}, {'name': 'PERIOD', 'type': 'string', 'typeCode': 0, 'size': 255, 'length': 254}, {'name': 'VOL', 'type': 'string', 'typeCode': 0, 'size': 255, 'length': 254}, {'name': 'SHAPE_LENG', 'type': 'double', 'typeCode': 5, 'size': 8, 'length': 20, 'decimal': 15}, {'name': 'SHAPE_AREA', 'type': 'double', 'typeCode': 5, 'size': 8, 'length': 20, 'decimal': 15}]

MapGisFile.getCapabilities

def getCapabilities(
       self
) -> Union[dict, None]

获取 MapGIS 点线面图形文件的基本信息字典

返回图形文件的基本信息字典对象,无效时返回None,失败时抛出异常

  • 示例
>>> # 创建实例:
>>> mapgis = giser.MapGisFile('.\\Data\\WP.WP')
>>> print(mapgis.getCapabilities())
>>> # {'type': 'FeatureCollection', 'fileType': 'Polygon', 'timeStamp': '2024-08-01T13:30:37+0800', 'name': 'WP', 'bbox': [99.62185619, 36.5514238, 100.75856675, 37.23177728], 'crs': {'type': 'name', 'properties': {'name': 'EPSG:0', 'parameters': {'projectionTypeCode': 0, 'fileTypeCode': 2, 'ellipsoidCode': 0, 'unitsCode': 0, 'central_meridian': 0.0, 'latitude_of_origin': 0.0, 'standard_parallel_1': 0.0, 'standard_parallel_2': 0.0, 'false_easting': 0.0, 'false_northing': 0.0, 'ellipsoidElevation': 0.0, 'projectionElevation': 0.0}, 'crs': None}}, 'properties': {'fieldCount': 11, 'featureCount': 1}}

MapGisFile.getFeature

def getFeature(
       self
) -> Iterator

迭代获取 MapGIS 点线面图形文件内可枚举的有效要素对象。注:推荐采用实例属性[RecordCount]获取可枚举的要素总数(含已删除的要素),采用实例属性[FeatureCount]获取有效要素个数(不含已删除的要素)

依次返回可枚举的单个有效要素对象,失败时抛出异常

  • 示例
>>> # 创建实例:
>>> mapgis = giser.MapGisFile('.\\Data\\WP.WP')
>>> for feature in mapgis.getFeature():
>>>     print(feature)
>>>     # 返回的每个要素字典的属性包括:type、id、geometry、style、properties、timeStamp
>>>     # {'type': 'Feature', 'id': 0, 'geometry': {'type': 'Polygon', 'coordinates': [[[100.00147174, 37.2198217], [100.00278156, 37.21862992],..., [100.00147174, 37.2198217]], [[100.12517688, 36.86915038], ..., [100.12517688, 36.86915038]]]}, 'style': {'fillColor': '#000000', 'fillPattern': 0, 'patternHeight': 0.0, 'patternWidth': 0.0, 'lineWidth': 0, 'patternColor': '#000000', 'layer': 0, 'transparent': 1}, 'properties': {'ID': {'type': 'long', 'length': 8, 'value': 0}, '面积': {'type': 'double', 'length': 15, 'decimal': 6, 'value': 0.424104}, '周长': {'type': 'double', 'length': 15, 'decimal': 6, 'value': 4.185338}, 'OBJECTID': {'type': 'long', 'length': 20, 'value': 12643}, 'GB': {'type': 'long', 'length': 20, 'value': 230101}, 'HYDC': {'type': 'string', 'length': 254, 'value': 'KK00561L'}, 'NAME': {'type': 'string', 'length': 254, 'value': '青海湖(库库诺尔)'}, 'PERIOD': {'type': 'string', 'length': 254, 'value': ''}, 'VOL': {'type': 'string', 'length': 254, 'value': ''}, 'SHAPE_LENG': {'type': 'double', 'length': 20, 'decimal': 15, 'value': 4.185338020324707}, 'SHAPE_AREA': {'type': 'double', 'length': 20, 'decimal': 15, 'value': 0.4241042137146}}, 'timeStamp': '2024-08-01T13:30:37+0800'}

MapGisFile.saveAsGeoJson

def saveAsGeoJson(
       self, fileName: str
) -> None

将 MapGIS 要素导出为GeoJson文本文件,支持超大文件存储。注:执行过程中将持续广播'progress'消息并携带进度对象{'index': 当前索引位, 'count': 总数量}

Parameter Type Description
fileName str 欲存盘的GeoJson文件名

失败时抛出异常(如:文件无法创建、文件不具有写权限、磁盘已满等)

  • 示例
>>> # 创建实例:
>>> mapgis = giser.MapGisFile('.\\Data\\WP.WP') 
>>> # 可选:定义一个消息事件句柄(槽函数),以便接收并响应进度消息
>>> def messageSlot(data):
>>>     print('Progress Message:', data)
>>> # 可选:订阅进度消息
>>> mapgis.subscribe('progress', messageSlot)
>>> # 导出至磁盘文件
>>> mapgis.saveAsGeoJson('WP.json')

  • class Projection(GiserBase)

    几何要素坐标投影变换类,支持高斯-克吕格、球体墨卡托、阿尔勃斯、兰伯特投影正反算

Projection.angle

@staticmethod
def angle(
       deg: Union[float, str] = None, dms: Union[float, str] = None, digit: Union[int, str] = None
) -> Union[float, str]

十进制角度与六十进制度分秒转换函数,优先识别十进制角度(deg),其次识别六十进制度分秒(dms)

Parameter Type Description
deg Union[float, str] 十进制角度,定义域为:[-360 ~ +360]。如果同时指定了[deg]和[dms]参数,[deg]参数将优先识别并忽略[dms]参数
dms Union[float, str] 六十进制度分秒,度的定义域为:[-360 ~ +360],格式为:十进制度、度分分秒秒、x度xx分xx秒、x°x′x.x″
digit Union[int, str] 秒值的小数位(0:按四舍五入取整;大于0:按四舍五入取指定位数;忽略时取默认值:双精度最长有效位)

返回转换结果(deg -> dms 返回字符串; dms -> deg 返回浮点数值)。失败时抛出异常

示例:

Projection.angle(deg=123.456789) 
# 123°27′24.440400000002″
Projection.angle(dms='123°27′24.4404″')
# 123.456789
Projection.angle(dms='123度27分24.4404秒')
# 123.456789
Projection.angle(dms='27分24.4404秒')
# 0.456789
Projection.angle(dms='1232724.4404')
# 123.456789

Projection.geodesics

@classmethod
def geodesics(
       cls,
       point1: Union[list, tuple],
       point2: Union[list, tuple],
       crs: int = 1984
) -> Union[float, None]

依据文森蒂(Vincenty)算法计算指定椭球体表面上两点之间的测地线长度(米制)

Parameter Type Description
point1 list, tuple 第一个点坐标,十进制经纬度格式,经度定义域为:[-180 ~ +180],纬度定义域为:[-90 ~ +90]
point2 list, tuple 第二个点坐标,十进制经纬度格式,经度定义域为:[-180 ~ +180],纬度定义域为:[-90 ~ +90]
crs int 坐标参照系年代(1954=北京坐标系;1980=西安坐标系;1984=WGS84坐标系;2000=CGCS2000坐标系,省略取默认值:1984)

返回两点间的测地线长度。无效时返回None,失败时抛出异常

示例:

geodesics((0.0, 0.0), (0.0, 0.0))
# 0.0
geodesics((0.0, 0.0), (179.7, 0.5))
# None
geodesics((108.9423662424, 34.2610116842), (116.3913112879, 39.9055966108))  # 西安 北京
# 910985.9111078943

Projection.zone

@classmethod
def zone(
       cls,
       longitude: float,
       zoneCode: int = 6
) -> int

由指定经度计算六度带或者三度带带号(如果指定的经度恰好位于两个投影带的中间,便取右侧带号)

Parameter Type Description
longitude float 经度(十进制度),定义域为:[-180 ~ +180]
zoneCode int 6或3,省略或无效时取默认值:6

返回六度或三度带带号。失败时抛出异常

Projection.centralMeridian

@classmethod
def centralMeridian(
       cls,
       longitude: float = None,
       zone: int = None,
       zoneCode: int = 6
) -> float

由指定的经度或者投影带带号计算所处6度或3度投影带中央子午线(经度)。如果同时指定了[longitude]和[zone]参数,将优先依据[longitude]参数计算中央子午线;如果两参数均未指定,便返回None

Parameter Type Description
longitude float 经度(十进制度),定义域为:[-180 ~ +180]
zone int 三度带带号(1~120)或者六度带带号(1~60)
zoneCode int 6或3,省略或无效时取默认值:6

返回中央子午线(十进制度,值域为:[-180 ~ +180])。失败时抛出异常

Projection.albers

@classmethod
def albers(
       cls,
       longitude: float = None,
       latitude: float = None,
       centralMeridian: float = 0,
       originLatitude: float = 0,
       parallel1: float = 20,
       parallel2: float = 50,
       x: float = None,
       y: float = None,
       crs: int = 2000
) -> tuple

阿尔伯斯球体双标准纬线等积割圆锥投影(Albers Equal Area Projection)正反算函数,优先识别地理经纬度坐标(longitude、latitude)执行正算,其次识别直角坐标(x、y)并执行反算

Parameter Type Description
longitude float 十进制经度,定义域为:[-180 ~ +180]
latitude float 十进制纬度,定义域为:[-90 ~ +90]
centralMeridian float 中央子午线经度(十进制度格式,默认值:0),定义域为:[-180 ~ +180]
originLatitude float 底点纬度(十进制度);默认值:0,定义域为:[-90 ~ +90]
parallel1 float 第一标准纬线(十进制度);默认值:20,定义域为:[-90 ~ +90]
parallel2 float 第二标准纬线(十进制度);默认值:50,定义域为:[-90 ~ +90]
x float 米制横坐标
y float 米制纵坐标
crs int 坐标参照系年代(1954=北京坐标系;1980=西安坐标系;1984=WGS84坐标系;2000=CGCS2000坐标系,省略取默认值:2000)

返回正反算结果元组(横坐标,纵坐标),失败时抛出异常

Projection.gaussKruger

@classmethod
def gaussKruger(
       cls,
       centralMeridian: float = None,
       x: float = None,
       y: float = None,
       longitude: float = None,
       latitude: float = None,
       crs: int = 2000
) -> tuple

高斯克吕格投影正反算函数,优先识别直角坐标(x、y)执行反算,其次识别地理经纬度坐标(longitude、latitude)并执行正算

Parameter Type Description
centralMeridian float 中央子午线经度(十进制度格式,省略或空白取默认值:按六度分带自动识别)。注意:比例尺小于1万时通常采用六度分带,大于等于1万时采用三度分带
x float 纵坐标(米制)指向坐标北,与真北方向相差子午收敛角
y float 横坐标(米制,可含带号)通用值或自然值
longitude float 经度(十进制度格式),定义域为:[-180 ~ +180]
latitude float 纬度(十进制度格式),定义域为:[-90 ~ +90]
crs int 坐标参照系年代(1954=北京坐标系;1980=西安坐标系;1984=WGS84坐标系;2000=CGCS2000坐标系,省略取默认值:2000)

返回正反算结果元组(横坐标,纵坐标)。正算时返回米制纵坐标和横坐标的(含带号)通用值;反算时返回十进制经纬度。失败时抛出异常

Projection.lambert

@classmethod
def lambert(
       cls,
       longitude: float = None,
       latitude: float = None,
       centralMeridian: float = 0,
       originLatitude: float = 0,
       parallel1: float = 20,
       parallel2: float = 50,
       x: float = None,
       y: float = None,
       crs: int = 2000
) -> tuple

兰伯特双标准纬线等角割圆锥投影(Lambert Conformal Projection)正反算函数,优先识别地理经纬度坐标(longitude、latitude)执行正算,其次识别直角坐标(x、y)并执行反算

Parameter Type Description
longitude float 十进制经度,定义域为:[-180 ~ +180]
latitude float 十进制纬度,定义域为:[-90 ~ +90]
centralMeridian float 中央子午线经度(十进制度格式,默认值:0),定义域为:[-180 ~ +180]
originLatitude float 底点纬度(十进制度);默认值:0,定义域为:[-90 ~ +90]
parallel1 float 第一标准纬线(十进制度);默认值:20,定义域为:[-90 ~ +90]
parallel2 float 第二标准纬线(十进制度);默认值:50,定义域为:[-90 ~ +90]
x float 米制横坐标
y float 米制纵坐标
crs int 坐标参照系年代(1954=北京坐标系;1980=西安坐标系;1984=WGS84坐标系;2000=CGCS2000坐标系,省略取默认值:2000)

返回正反算结果元组(横坐标,纵坐标)。失败时抛出异常

Projection.webMercator

@classmethod
def webMercator(
       cls,
       longitude: float = None,
       latitude: float = None,
       x: float = None,
       y: float = None
) -> tuple

球体墨卡托投影(WGS84坐标系)正反算函数,优先识别地理经纬度坐标(longitude、latitude)执行正算,其次识别直角坐标(x、y)并执行反算

Parameter Type Description
longitude float 十进制经度,定义域为:[-180 ~ +180]
latitude float 十进制纬度,定义域为:[-90 ~ +90]
x float 米制横坐标
y float 米制纵坐标

返回正反算结果元组(横坐标,纵坐标)。失败时抛出异常


  • class MapGrid(GiserBase)

    国际标准比例尺图幅分幅网格与编号类

    支持比例尺:1∶1000000、1∶500000、1∶250000、1∶200000(非国际标准)、1∶100000、1∶50000、1∶25000、1∶10000、1∶5000、1∶2000、1∶1000、1∶500

    算法依据《中华人民共和国国家标准 GB/T 13989-2012 国家基本比例尺地形图分幅和编号》(2012-06-29发布 2012-10-01实施)


MapGrid.map

@classmethod
def map(
       cls,
       longitude: float,
       latitude: float,
       scale: int = 1000000
) -> dict

由十进制经纬度位置和比例尺分母计算所在比例尺的图幅新旧编号(南半球冠以S前缀,北半球省略N前缀)与边框范围。注:如果指定位置恰好位于图幅边缘,将返回右上角图幅结果信息

Parameter Type Description
longitude float 十进制经度,定义域为:[-180 ~ +180]
latitude float 十进制纬度,定义域为:[-90 ~ +90]
scale int 比例尺分母,定义域为:[1000000(默认) ~ 500]

返回所在比例尺的图幅新旧编号与边框范围构成的字典对象,运行失败时抛出异常

示例(位置:114°33′45″,39°22′30″):

giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=1000000)  
# {'new': 'J50', 'old': 'J-50', 'boundary': {'north': 40, 'south': 36, 'west': 114, 'east': 120}}  
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=500000)  
# {'new': 'J50B001001', 'old': 'J-50-A', 'boundary': {'north': 40.0, 'south': 38.0, 'west': 114.0, 'east': 117.0}}  
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=250000)  
# {'new': 'J50C001001', 'old': 'J-50-[1]', 'boundary': {'north': 40.0, 'south': 39.0, 'west': 114.0, 'east': 115.5}}  
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=200000)   
# {'new': 'J-50-(01)', 'old': 'J-50-(01)', 'boundary': {'north': 40.0, 'south': 39.333333333333336, 'west': 114.0, 'east': 115.0}}   
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=100000)  
# {'new': 'J50D002002', 'old': 'J-50-14', 'boundary': {'north': 39.66666666666667, 'south': 39.333333333333336, 'west': 114.5, 'east': 115.0}}  
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=50000)  
# {'new': 'J50E004003', 'old': 'J-50-14-C', 'boundary': {'north': 39.5, 'south': 39.333333333333336, 'west': 114.5, 'east': 114.75}}  
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=25000)  
# {'new': 'J50F008005', 'old': 'J-50-14-C-3', 'boundary': {'north': 39.41666666666667, 'south': 39.333333333333336, 'west': 114.5, 'east': 114.625}}  
giser.MapGrid.map(long010', 'itude=114.5625, latitude=39.375, scale=10000)
# {'new': 'J50G015old': 'J-50-14-(50)', 'boundary': {'north': 39.416666666666664, 'south': 39.375, 'west': 114.5625, 'east': 114.625}}  
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=5000)
# {'new': 'J50H030019', 'old': 'J-50-14-(50)-c', 'boundary': {'north': 39.395833333333336, 'south': 39.375, 'west': 114.5625, 'east': 114.59375}}  
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=2000)  
# {'new': 'J50I090055', 'old': 'J-50-14-(50)-c-7', 'boundary': {'north': 39.38194444444444, 'south': 39.375, 'west': 114.5625, 'east': 114.57291666666667}}  
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=1000)
# {'new': 'J50J01800109', 'old': 'J-50-14-(50)-c-7-3', 'boundary': {'north': 39.37847222222222, 'south': 39.375, 'west': 114.5625, 'east': 114.56770833333333}}   
giser.MapGrid.map(longitude=114.5625, latitude=39.375, scale=500)
# {'new': 'J50K03600217', 'old': 'J-50-14-(50)-c-7-3-3', 'boundary': {'north': 39.376736111111114, 'south': 39.375, 'west': 114.5625, 'east': 114.56510416666667}}

MapGrid.parse

@classmethod
def parse(
       cls,
       code: str
) -> dict

由国家基本比例尺地形图分幅(新旧)编号解析图幅边界范围和比例尺信息

Parameter Type Description
code str 国家基本比例尺地形图分幅编号(忽略大小写)

返回图幅边界范围、比例尺构成的字典对象,运行失败时抛出异常

示例:

giser.MapGrid.parse('J50' 或者 'J-50')    
# {'scale': 1000000, 'boundary': {'north': 40, 'south': 36, 'west': 114, 'east': 120}}  
giser.MapGrid.parse('J50B001001' 或者 'J-50-A')  
# {'scale': 500000, 'boundary': {'north': 40.0, 'south': 38.0, 'west': 114.0, 'east': 117.0}}  
giser.MapGrid.parse('J50C001001' 或者 'J-50-[1]')  
# {'scale': 250000, 'boundary': {'north': 40.0, 'south': 39.0, 'west': 114.0, 'east': 115.5}}  
giser.MapGrid.parse('J-50-(01)')   
# {'scale': 200000, 'boundary': {'north': 40.0, 'south': 39.333333333333336, 'west': 114.0, 'east': 115.0}}    
giser.MapGrid.parse('J50D002002' 或者 'J-50-14')   
# {'scale': 100000, 'boundary': {'north': 39.66666666666667, 'south': 39.333333333333336, 'west': 114.5, 'east': 115.0}}  
giser.MapGrid.parse('J50E004003' 或者 'J-50-14-C')
# {'scale': 50000, 'boundary': {'north': 39.5, 'south': 39.333333333333336, 'west': 114.5, 'east': 114.75}}  
giser.MapGrid.parse('J50F008005' 或者 'J-50-14-C-3')
# {'scale': 25000, 'boundary': {'north': 39.41666666666667, 'south': 39.333333333333336, 'west': 114.5, 'east': 114.625}}   
giser.MapGrid.parse('J50G015010' 或者 'J-50-14-(50)')
# {'scale': 10000, 'boundary': {'north': 39.416666666666664, 'south': 39.375, 'west': 114.5625, 'east': 114.625}}  
giser.MapGrid.parse('J50H030019' 或者 'J-50-14-(50)-c')
# {'scale': 5000, 'boundary': {'north': 39.395833333333336, 'south': 39.375, 'west': 114.5625, 'east': 114.59375}}  
giser.MapGrid.parse('J50I090055' 或者 'J-50-14-(50)-c-7')
# {'scale': 2000, 'boundary': {'north': 39.38194444444444, 'south': 39.375, 'west': 114.5625, 'east': 114.57291666666667}}  
giser.MapGrid.parse('J50J01800109' 或者 'J-50-14-(50)-c-7-3')
# {'scale': 1000, 'boundary': {'north': 39.37847222222222, 'south': 39.375, 'west': 114.5625, 'east': 114.56770833333333}}  
giser.MapGrid.parse('J50K03600217' 或者 'J-50-14-(50)-c-7-3-3')
# {'scale': 500, 'boundary': {'north': 39.376736111111114, 'south': 39.375, 'west': 114.5625, 'east': 114.56510416666667}}

MapGrid.grid

@staticmethod
def grid(
       north: float,
       south: float,
       west: float,
       east: float,
       zoom: int = 0,
       summary: bool = False
) -> Iterator

依据视图窗口边框范围和缩放级获取国家基本比例尺地形图分幅经纬网格线(适宜于GIS图形视窗呈现),视窗边界参数将充当经纬网线段的裁剪框

Parameter Type Description
north float 视窗北边界坐标(十进制纬度),定义域为:[-90 ~ +90]
south float 视窗南边界坐标(十进制纬度),定义域为:[-90 ~ +90]
west float 视窗西边界坐标(十进制经度),定义域为:[-180 ~ +180]
east float 视窗东边界坐标(十进制经度),定义域为:[-180 ~ +180]
zoom int 缩放级,默认:0。注:缩放级对应的比例尺为:小于等于5级=1∶1000000;6级=1∶500000;7级=1∶250000;8级=1∶200000;9级=1∶100000;10级=1∶50000;11级=1∶25000;12级=1∶10000;13级=1∶5000;14级=1∶2000;15级=1∶1000;大于等于16级=1∶500
summary bool 是否仅返回概要信息,默认:False

如果summary取默认值False,将返回线段类型标识与经纬网和比例尺分母联合构成的枚举型字典迭代器(Iterator);如果summary设为True,将返回经纬线个数与经纬线步长和比例尺分母联合构成的枚举型字典迭代器(Iterator)。失败时抛出异常

获取经纬网信息示例:

[print(line) for line in giser.MapGrid.grid(40, 20, 80, 100, 0)]  
# 运行结果:
# {'remarks': 'longitude', 'type': 'LineString', 'coordinates': [[84.0, 20.0], [84.0, 40.0]], 'scale': 1000000}
# ......
# {'remarks': 'latitude', 'type': 'LineString', 'coordinates': [[80, 20.0], [100, 20.0]], 'scale': 1000000}
# ......

  • class Geometry(GiserBase)

地学几何要素加载、编码、转换与序列化类,几何要素主体采用{Python-dict}类型存储并符合{GeoJson-geometry}格式要求。

支持的几何文本格式如下:

● GeoJSON             A format for encoding a variety of geographic data structures. RFC 7946 was published in August 2016 and is the new standard specification of the GeoJSON format.

● WKT                 ISO 19162:2015(E) - Well-known Text (WKT) offers a compact machine- and human-readable representation of geometric objects.

支持的几何类型如下:

● Point               A geometry type that represents a single coordinate with x,y and possibly z,m values.
● LineString          A geometry type composed of one or more line segments.
● Polygon             A geometry type representing an area that is enclosed by a linear ring.
● MultiPoint          A collection of one or more Points.
● MultiLineString     A collection of one or more LineStrings.
● MultiPolygon        A collection of one or more Polygons.
● GeometryCollection  A collection of one or more geometries that may contain more than one type of geometry.

Geometry.loads

@classmethod
def loads(
        cls,
        coordinates: str | list | dict,
        code: int | None = -1
) -> dict

加载符合【自由/简约文本、WKT、GeoJson】文本格式的几何坐标串或符合【GeoJson-geometry】格式的列表对象以及符合【GeoJson-geometry】格式的字典类型对象。

注1:针对线和面要素,将自动剔除相邻重复点,面要素的线环将自动封闭。

注2:针对顶点坐标,要求至少是二维,且前两个维度应为浮点数值,为提升普适度,不对浮点型[x y]的定义域进行约束。

注3:如果GeoJson以文本方式输入,其中的对象名必须采用双引号封闭。

Parameter Type Description
coordinates str list dict 几何坐标参数(不多于4维[x y z m]且要求前2维[x y]为浮点型)。其中,GeoJson格式需具有[方括号]标识,WKT格式需具有(圆括号)标识,自由格式仅识别【单点/单线/单面】几何类型
code int None 几何类型代码:-1=自识别(默认值)、0=单点/多点、1=单线/多线、2=单面或母子面/多面。注:此参数通常仅当输入的坐标为简约格式且期望格式为[多点/多线]时需指定为[0/1],或者当输入的坐标为自由格式时也应指定为[0/1/2],以便消除二义性问题

返回符合【GeoJson-geometry】格式的字典类型对象,字典中的【type】成员为几何类型名称,【coordinates】成员为符合GeoJson格式的浮点型几何坐标数组。失败时抛出异常

  • coordinates 参数格式说明

  • 自由文本格式(仅支持2维)

    • Point:code参数可为[0]或者[-1]
      'x y'
      'x,y'
    • LineString:code参数可为[1]或者[-1],若code指定为0,便视为多点[MultiPoint]
      'x y,x y,...'
      'x,y x,y ...'
    • Polygon:code参数必须指定为[2]方可视为单面[Polygon],若code指定为0,便视为多点[MultiPoint],若code指定为1,便视为单线[LineString]
      'x y,x y,x y,x y,...'
      'x,y x,y x,y x,y ...'
  • GeoJson

    • Point:
      [x,y,z,m] # 简约格式
      {"type":"Point","coordinates":[x,y,z,m]}
    • MultiPoint:
      [[x,y,z,m],[x,y,z,m],...] # 简约格式
      {"type":"MultiPoint","coordinates":[[x,y,z,m],[x,y,z,m],...]}
    • LineString:
      [[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],...] # 简约格式
      {"type":"LineString","coordinates":[[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],...]}
    • MultiLineString:
      [[[x,y,z,m],[x,y,z,m],[x,y,z,m]],[[x,y,z,m],[x,y,z,m],[x,y,z,m],...],...] # 简约格式
      {"type":"MultiLineString","coordinates":[[[x,y,z,m],[x,y,z,m],[x,y,z,m]],[[x,y,z,m],[x,y,z,m],[x,y,z,m],...],...]}
    • Polygon(单面或母子面):
      [[[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],...],...] # 简约格式
      {"type":"Polygon","coordinates":[[[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],...],...]}
    • MultiPolygon:
      [[[[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],...],...],...] # 简约格式
      {"type":"MultiPolygon","coordinates":[[[[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],...],...],...]}
    • GeometryCollection:
      {'type': 'GeometryCollection', 'geometries': [{"type":"Point","coordinates":[x,y,z,m]}, {"type":"LineString","coordinates":[[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],...]}, {"type":"Polygon","coordinates":[[[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],[x,y,z,m],...],...]}]}
  • WKT(Well-Known Text 采用文本字符串存储)

    • Point:
      (x y z m) # 简约格式
      POINT(x y z m)
    • MultiPoint:
      (x y z m,x y z m,...) # 简约格式
      MULTIPOINT(x y z m,x y z m,...)
    • LineString:
      (x y z m,x y z m,...) # 简约格式
      LINESTRING(x y z m,x y z m,...)
    • MultiLineString:
      ((x y z m,x y z m,...),...) # 简约格式
      MULTILINESTRING((x y z m,x y z m,...),...)
    • Polygon(单面或母子面):
      ((x y z m,x y z m,...),...) # 简约格式
      POLYGON((x y z m,x y z m,...),...)
    • MultiPolygon:
      (((x y z m,x y z m,...),...),...)
      MULTIPOLYGON(((x y z m,x y z m,...),...),...)
    • GEOMETRYCOLLECTION(不支持简约格式):
      GEOMETRYCOLLECTION(POINT(x y z m), LINESTRING(x y z m,x y z m,...), POLYGON((x y z m,x y z m,...),...))
  • 自由文本格式示例

# Point
>>> giser.Geometry.loads('120,38', -1 or 0)   
>>> giser.Geometry.loads('120 38', -1 or 0)   
# {'type': 'Point', 'coordinates': [120, 38]}
# MultiPoint
>>> giser.Geometry.loads('120 38,122 39,99 28,120 38', 0)   
>>> giser.Geometry.loads('120,38 122,39 99,28 120,38', 0)  
# {'type': 'MultiPoint', 'coordinates': [[120, 38], [122, 39], [99, 28], [120, 38]]}  
# LineString
>>> giser.Geometry.loads('120 38,122 39,99 28,120 38', -1 or 1)   
>>> giser.Geometry.loads('120,38 122,39 99,28 120,38', -1 or 1)  
# {'type': 'LineString', 'coordinates': [[120, 38], [122, 39], [99, 28], [120, 38]]}  
# Polygon
>>> giser.Geometry.loads('120 38,122 39,99 28,120 38', 2)    
>>> giser.Geometry.loads('120,38 122,39 99,28 120,38', 2)   
# {'type': 'Polygon', 'coordinates': [[[120, 38], [122, 39], [99, 28], [120, 38]]]}    
  • GeoJSON 格式示例
# Point
>>> giser.Geometry.loads([-115.81, 37.24],-1 or 0)     
>>> giser.Geometry.loads('[-115.81, 37.24]',-1 or 0)    
>>> giser.Geometry.loads('{"type": "Point", "coordinates": [-115.81, 37.24]}', -1 or 0)  
>>> giser.Geometry.loads({"type": "Point", "coordinates": [-115.81, 37.24]},-1 or 0)  
# {'type': 'Point', 'coordinates': [-115.81, 37.24]}   
# MultiPoint / LineString  
>>> giser.Geometry.loads([[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]], 0)     
>>> giser.Geometry.loads('[[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]]', 0)   
>>> giser.Geometry.loads('{"type":"MultiPoint","coordinates":[[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]]}',-1 or 0)  
>>> giser.Geometry.loads({"type":"MultiPoint","coordinates":[[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]]},-1 or 0)  
# {'coordinates': [[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]], 'type': 'MultiPoint'}    
>>> giser.Geometry.loads([[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]], -1 or 1)    
>>> giser.Geometry.loads('[[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]]', -1 or 1)  
# {'coordinates': [[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]], 'type': 'LineString'}  
# LineString   
>>> giser.Geometry.loads([[8.919, 44.4074], [8.923, 44.4075]], -1 or 1)  
>>> giser.Geometry.loads('[[8.919, 44.4074], [8.923, 44.4075]]', -1 or 1)  
>>> giser.Geometry.loads('{"type":"LineString","coordinates": [[8.919, 44.4074], [8.923, 44.4075]]}', -1 or 1)  
>>> giser.Geometry.loads({"type":"LineString","coordinates": [[8.919, 44.4074], [8.923, 44.4075]]}, -1 or 1)  
# {'coordinates': [[8.919, 44.4074], [8.923, 44.4075]], 'type': 'LineString'}    
# MultiLineString / Polygon    
>>> giser.Geometry.loads([[[3.75, 9.25], [-130.95, 1.52]], [[23.15, -34.25], [-1.35, -4.65], [3.45, 77.95]]], 1)   
>>> giser.Geometry.loads('[[[3.75, 9.25], [-130.95, 1.52]], [[23.15, -34.25], [-1.35, -4.65], [3.45, 77.95]]]', 1)   
>>> giser.Geometry.loads('{"type":"MultiLineString","coordinates":[[[3.75, 9.25], [-130.95, 1.52]], [[23.15, -34.25], [-1.35, -4.65], [3.45, 77.95]]]}', -1 or 1)  
>>> giser.Geometry.loads({"type":"MultiLineString","coordinates":[[[3.75, 9.25], [-130.95, 1.52]], [[23.15, -34.25], [-1.35, -4.65], [3.45, 77.95]]]}, -1 or 1)  
# {'type': 'MultiLineString', 'coordinates': [[[3.75, 9.25], [-130.95, 1.52]], [[23.15, -34.25], [-1.35, -4.65], [3.45, 77.95]]]}   
# no hole within polygon  
>>> giser.Geometry.loads([[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]], -1 or 2)  
>>> giser.Geometry.loads('[[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]]', -1 or 2)  
>>> giser.Geometry.loads('{"type":"Polygon","coordinates":[[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]]}', -1 or 2)  
>>> giser.Geometry.loads({"type":"Polygon","coordinates":[[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]]}, -1 or 2)  
# {'type': 'Polygon', 'coordinates': [[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]]}  
# hole within polygon   
>>> giser.Geometry.loads('{"type":"Polygon","coordinates":[[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]], [[-5.21, 23.51], [15.21, -10.81], [-20.51, 1.51], [-5.21, 23.51]]]}', -1 or 2)  
>>> giser.Geometry.loads({"type":"Polygon","coordinates":[[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]], [[-5.21, 23.51], [15.21, -10.81], [-20.51, 1.51], [-5.21, 23.51]]]}, -1 or 2)  
>>> giser.Geometry.loads('[[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]], [[-5.21, 23.51], [15.21, -10.81], [-20.51, 1.51], [-5.21, 23.51]]]', -1 or 2)  
>>> giser.Geometry.loads([[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]], [[-5.21, 23.51], [15.21, -10.81], [-20.51, 1.51], [-5.21, 23.51]]], -1 or 2)          
# {'type': 'Polygon', 'coordinates': [[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]], [[-5.21, 23.51], [15.21, -10.81], [-20.51, 1.51], [-5.21, 23.51]]]}  
# MultiPolygon   
>>> giser.Geometry.loads('{"type":"MultiPolygon","coordinates":[[[[3.78, 9.28], [-130.91, 1.52], [35.12, 72.234], [3.78, 9.28]]], [[[23.18, -34.29], [-1.31, -4.61], [3.41, 77.91], [23.18, -34.29]]]]}', -1 or 2)  
>>> giser.Geometry.loads({"type":"MultiPolygon","coordinates":[[[[3.78, 9.28], [-130.91, 1.52], [35.12, 72.234], [3.78, 9.28]]], [[[23.18, -34.29], [-1.31, -4.61], [3.41, 77.91], [23.18, -34.29]]]]}, -1 or 2)  
>>> giser.Geometry.loads('[[[[3.78, 9.28], [-130.91, 1.52], [35.12, 72.234], [3.78, 9.28]]], [[[23.18, -34.29], [-1.31, -4.61], [3.41, 77.91], [23.18, -34.29]]]]', -1 or 2)  
>>> giser.Geometry.loads([[[[3.78, 9.28], [-130.91, 1.52], [35.12, 72.234], [3.78, 9.28]]], [[[23.18, -34.29], [-1.31, -4.61], [3.41, 77.91], [23.18, -34.29]]]], -1 or 2)           
# {'type': 'MultiPolygon', 'coordinates': [[[[3.78, 9.28], [-130.91, 1.52], [35.12, 72.234], [3.78, 9.28]]], [[[23.18, -34.29], [-1.31, -4.61], [3.41, 77.91], [23.18, -34.29]]]]}  
# GeometryCollection(不支持简约格式且可忽略识别码)    
>>> giser.Geometry.loads({"type": "GeometryCollection","geometries":[{"type": "Point", "coordinates": [-115.81, 37.24]},{"type":"LineString","coordinates": [[8.919, 44.4074], [8.923, 44.4075]]},{"type":"Polygon","coordinates":[[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]]}]})  
>>> giser.Geometry.loads('{"type": "GeometryCollection","geometries":[{"type": "Point", "coordinates": [-115.81, 37.24]},{"type":"LineString","coordinates": [[8.919, 44.4074], [8.923, 44.4075]]},{"type":"Polygon","coordinates":[[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]]}]}')      
# {'type': 'GeometryCollection', 'geometries': [{'type': 'Point', 'coordinates': [-115.81, 37.24]}, {'type': 'LineString', 'coordinates': [[8.919, 44.4074], [8.923, 44.4075]]}, {'type': 'Polygon', 'coordinates': [[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]]}]}   
  • WKT 格式示例
# Point  
>>> giser.Geometry.loads('POINT(-115.81 37.24)', -1 or 0)   
>>> giser.Geometry.loads('(-115.81 37.24)', -1 or 0)   
# {'type': 'Point', 'coordinates': [-115.81, 37.24]}   
# MultiPoint / LineString     
>>> giser.Geometry.loads('MULTIPOINT(-155.52 19.61,-156.22  20.74,-157.97  21.46)', -1 or 0)  
>>> giser.Geometry.loads('(-155.52 19.61,-156.22  20.74,-157.97  21.46)', 0)  
# {'type': 'MultiPoint', 'coordinates': [[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]]}   
>>> giser.Geometry.loads('(-155.52 19.61,-156.22  20.74,-157.97  21.46)', -1)   
# {'type': 'LineString', 'coordinates': [[-155.52, 19.61], [-156.22, 20.74], [-157.97, 21.46]]}  
# LineString   
>>> giser.Geometry.loads('LINESTRING(8.919 44.4074,8.923 44.4075)', -1 or 1)    
>>> giser.Geometry.loads('(8.919 44.4074,8.923 44.4075)', -1 or 1)   
# {'type': 'LineString', 'coordinates': [[8.919, 44.4074], [8.923, 44.4075]]}   
# MultiLineString / Polygon  
>>> giser.Geometry.loads('MULTILINESTRING((3.75 9.25,-130.95 1.52),(23.15 -34.25,-1.35 -4.65,3.45 77.95))', -1 or 1)  
>>> giser.Geometry.loads('((3.75 9.25,-130.95 1.52),(23.15 -34.25,-1.35 -4.65,3.45 77.95))', 1)  
# {'type': 'MultiLineString', 'coordinates': [[[3.75, 9.25], [-130.95, 1.52]], [[23.15, -34.25], [-1.35, -4.65], [3.45, 77.95]]]}  
>>> giser.Geometry.loads('((3.75 9.25,-130.95 1.52),(23.15 -34.25,-1.35 -4.65,3.45 77.95))', -1)  
# {'type': 'Polygon', 'coordinates': [[[3.75, 9.25], [-130.95, 1.52]], [[23.15, -34.25], [-1.35, -4.65], [3.45, 77.95]]]}  
# no hole within polygon  
>>> giser.Geometry.loads('POLYGON((2.38 57.322,-120.43 19.15,23.194 -20.28,2.38 57.322))', -1 or 2)  
>>> giser.Geometry.loads('((2.38 57.322,-120.43 19.15,23.194 -20.28,2.38 57.322))', -1 or 2)  
# {'type': 'Polygon', 'coordinates': [[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38, 57.322]]]}  
# hole within polygon   
>>> giser.Geometry.loads('POLYGON((2.38 57.322,-120.43 19.15,23.194 -20.28,2.38 57.322),(-5.21 23.51,15.21 -10.81,-20.51 1.51,-5.21 23.51))', -1 or 2)  
>>> giser.Geometry.loads('((2.38 57.322,-120.43 19.15,23.194 -20.28,2.38 57.322),(-5.21 23.51,15.21 -10.81,-20.51 1.51,-5.21 23.51))', -1 or 2)  
# {'type': 'Polygon', 'coordinates': [[[2.38, 57.322], [-120.43, 19.15], [23.194, -20.28], [2.38], [57.322]], [[-5.21, 23.51], [15.21, -10.81], [-20.51, 1.51], [-5.21, 23.51]]]}  
# MultiPolygon  
>>> giser.Geometry.loads('MULTIPOLYGON(((3.78 9.28,-130.91 1.52,35.12 72.234,3.78 9.28)),((23.18 -34.29,-1.31 -4.61,3.41 77.91,23.18 -34.29)))', -1 or 2)  
>>> giser.Geometry.loads('(((3.78 9.28,-130.91 1.52,35.12 72.234,3.78 9.28)),((23.18 -34.29,-1.31 -4.61,3.41 77.91,23.18 -34.29)))', -1 or 2)  
# {'type': 'MultiPolygon', 'coordinates': [[[[3.78, 9.28], [-130.91, 1.52], [35.12, 72.234], [3.78, 9.28]]], [[[23.18, -34.29], [-1.31, -4.61], [3.41, 77.91], [23.18, -34.29]]]]}  
# GeometryCollection(不支持简约格式且应将识别码取默认值[-1])    
>>> giser.Geometry.loads('GEOMETRYCOLLECTION (POINT (-115.81 37.24),LINESTRING (8.919 44.4074,8.923 44.4075),POLYGON ((2.38 57.322,-120.43 19.15,23.194 -20.28,2.38 57.322)))',-1)  
# {'type': 'GeometryCollection', 'geometries': [{'type': 'Point', 'coordinates': [-115.81, 37.24]}, {'type': 'LineString', 'coordinates': [[8.919, 44.4074], [8.923, 44.4075]]}]} 

Geometry.dumps

@classmethod
def dumps(
       cls,
       geometry: dict | list | str
) -> str  

将【GeoJson-geometry】几何字典对象序列化转储为GeoJson格式的字符串

Parameter Type Description
geometry dict list str 几何字典参数中的【type】成员为几何类型名称,【coordinates】成员为符合GeoJson格式的几何坐标数组

返回符合指定格式要求的字符串。失败时抛出异常

Geometry.toWkt

@classmethod
def toWkt(
        cls,
        geometry: dict | list | str
) -> str 

将【GeoJson-geometry】几何字典对象转换为OGC-WKT(Well-known Text)格式字符串

Parameter Type Description
geometry dict list str 几何字典参数中的【type】成员为几何类型名称,【coordinates】成员为符合GeoJson格式的几何坐标数组

返回WKT格式字符串。失败时抛出异常

Geometry.swapXY

@classmethod
def swapXY(
        cls,
        geometry: dict | list | str
) -> dict  

交换指定几何体的顶点坐标[x,y,z,m]中的[x,y]顺序([x,y,z,m] to [y,x,z,m])

Parameter Type Description
geometry dict list str 几何字典参数中的【type】成员为几何类型名称,【coordinates】成员为符合GeoJson格式的几何坐标数组

返回【GeoJson-geometry】格式的字典类型对象。失败时抛出异常

Geometry.getXY

@classmethod
def getXY(
        cls,
        geometry: dict | list | str,
        endpoint: bool = True  
) -> list

提取指定几何体的顶点(或端点)坐标并返回可哈希的坐标元组列表

Parameter Type Description
geometry dict list str GeoJSON几何字符串或字典对象以及列表对象,几何字典参数中的【type】成员为几何类型名称,【coordinates】成员为符合GeoJson格式的几何坐标数组
endpoint bool 是否仅提取端点?省略时取默认值:True。注:此选项仅针对线要素和面要素有效

返回坐标元组列表。失败时抛出异常

Contributing

Contributions are always welcome!

Authors

(C) 2019-2025 Geosite Development Team of CGS (R)

Support

For support, log in http://www.xacgs.cn or join our Community Discussion Channel.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

giserpy-2025.9.10-py314-none-win_amd64.whl (383.7 kB view details)

Uploaded Python 3.14Windows x86-64

giserpy-2025.9.10-py313-none-win_amd64.whl (374.9 kB view details)

Uploaded Python 3.13Windows x86-64

giserpy-2025.9.10-py313-none-manylinux_2_39_x86_64.whl (3.2 MB view details)

Uploaded Python 3.13manylinux: glibc 2.39+ x86-64

giserpy-2025.9.10-py313-none-macosx_13_0_x86_64.whl (967.2 kB view details)

Uploaded Python 3.13macOS 13.0+ x86-64

giserpy-2025.9.10-py312-none-win_amd64.whl (375.2 kB view details)

Uploaded Python 3.12Windows x86-64

giserpy-2025.9.10-py312-none-manylinux_2_39_x86_64.whl (3.2 MB view details)

Uploaded Python 3.12manylinux: glibc 2.39+ x86-64

giserpy-2025.9.10-py312-none-macosx_13_0_x86_64.whl (968.2 kB view details)

Uploaded Python 3.12macOS 13.0+ x86-64

giserpy-2025.9.10-py311-none-win_amd64.whl (391.8 kB view details)

Uploaded Python 3.11Windows x86-64

giserpy-2025.9.10-py311-none-manylinux_2_39_x86_64.whl (2.9 MB view details)

Uploaded Python 3.11manylinux: glibc 2.39+ x86-64

giserpy-2025.9.10-py311-none-macosx_13_0_x86_64.whl (993.2 kB view details)

Uploaded Python 3.11macOS 13.0+ x86-64

giserpy-2025.9.10-py310-none-win_amd64.whl (389.9 kB view details)

Uploaded Python 3.10Windows x86-64

giserpy-2025.9.10-py310-none-manylinux_2_39_x86_64.whl (2.8 MB view details)

Uploaded Python 3.10manylinux: glibc 2.39+ x86-64

giserpy-2025.9.10-py310-none-macosx_13_0_x86_64.whl (960.7 kB view details)

Uploaded Python 3.10macOS 13.0+ x86-64

giserpy-2025.9.10-py39-none-win_amd64.whl (390.4 kB view details)

Uploaded Python 3.9Windows x86-64

giserpy-2025.9.10-py39-none-manylinux_2_39_x86_64.whl (2.8 MB view details)

Uploaded Python 3.9manylinux: glibc 2.39+ x86-64

giserpy-2025.9.10-py39-none-macosx_13_0_x86_64.whl (961.4 kB view details)

Uploaded Python 3.9macOS 13.0+ x86-64

File details

Details for the file giserpy-2025.9.10-py314-none-win_amd64.whl.

File metadata

  • Download URL: giserpy-2025.9.10-py314-none-win_amd64.whl
  • Upload date:
  • Size: 383.7 kB
  • Tags: Python 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for giserpy-2025.9.10-py314-none-win_amd64.whl
Algorithm Hash digest
SHA256 fdc96dc4b47f351f34bcdc4ec378f6b7ece7976307b490ed96996075939c9c23
MD5 04cab47c1d84b14f01193e096cc243be
BLAKE2b-256 f8937a5c2b63c0d26e6bd39e8bac3d6b745a6bab26836ebe0c81026dcfeebd54

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py313-none-win_amd64.whl.

File metadata

  • Download URL: giserpy-2025.9.10-py313-none-win_amd64.whl
  • Upload date:
  • Size: 374.9 kB
  • Tags: Python 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for giserpy-2025.9.10-py313-none-win_amd64.whl
Algorithm Hash digest
SHA256 7917ddb62e81430b07f3339e412d4133d8251aaebcfc811f026f0ea3e7e17e3d
MD5 15748b8c99f74dd611c8987f4abbbb11
BLAKE2b-256 350e1678077419c7d7b1259cd88da97296728a8d24aa62512eb9f4969418e5c9

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py313-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py313-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 aa39ca24f343dcc1d72c2026d6680825743361fafb03b75384236cb08637127f
MD5 460ff898834eb9862e711361bda3cee3
BLAKE2b-256 44ba9a86f4341838536228f6ff220571f45ab69d69329e05fa777794f99f0d30

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py313-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py313-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 050e83ca2d39f1e4d6b9bc1c929ba293867d6227a51bdabc9d4f1ae4d52be3f9
MD5 a82e7b839db5cf76dfd481a7c5dc3227
BLAKE2b-256 1ea2abd1cf88759a4234f5ca6588e0795bbab781e6c718942f66b267d2fdc649

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py312-none-win_amd64.whl.

File metadata

  • Download URL: giserpy-2025.9.10-py312-none-win_amd64.whl
  • Upload date:
  • Size: 375.2 kB
  • Tags: Python 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for giserpy-2025.9.10-py312-none-win_amd64.whl
Algorithm Hash digest
SHA256 bb4cface423d59968caf2caf285c1b713a3f7e284a3418526ffb8b50e4a37420
MD5 ba285869cf3c731b1ea66fd917467f68
BLAKE2b-256 6bfa145da3e74fdc7905a87e1375b808da4bc471046294680a907727150be401

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py312-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py312-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 0fe77e27698d5bdf7d496103c0e349511172554a3e2ec1b7f2b30e6944f638f1
MD5 a331b40d0340c03bccdc3c1f405e0a3b
BLAKE2b-256 81cb785dcd9105815f991aee85d07178229821d7b018a46f61b83540c0f03aeb

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py312-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py312-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 94ec8c21fd4269d0cf62cf2a23f24578abeeb5b054a4e82cf8f569c9a5ed08ce
MD5 44906c7a13e69ccdd4420b118b4f89de
BLAKE2b-256 30a4dcf373671f4483e11a8ff94126b5e008e2ec0e38f3b18e3e0d1cc86c9d55

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py311-none-win_amd64.whl.

File metadata

  • Download URL: giserpy-2025.9.10-py311-none-win_amd64.whl
  • Upload date:
  • Size: 391.8 kB
  • Tags: Python 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for giserpy-2025.9.10-py311-none-win_amd64.whl
Algorithm Hash digest
SHA256 71fab6a67b255e743e74a68d2ed35bb098db446d7824a4e4fe56583f03f2b7f7
MD5 333effd02fc1eca82709cd4b47af6121
BLAKE2b-256 fdd45ebf5af605b3f53da1105e952b2886ef1336a670a9feee79ab2bd4f4ba4b

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py311-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py311-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 47948660b4228695a45ff2acc8c623cbf272d09e9b03e00e5ddafb1c8465768d
MD5 bb1a9f8ea237f6d20db26b7161b3de16
BLAKE2b-256 bcedbc4616286a8c192bd22aa566721b794075452b518f0932267e65da041253

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py311-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py311-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 92a22f40714218d5941f0bf7022e1bc316e6a7a9f1f6a7444bd85cf7f829b845
MD5 fa5b138be778ab2ce9dccfe62059579b
BLAKE2b-256 a857ed0238fc4303dc7a471c73f562d0f2653eabe3488878bef6008be09c9407

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py310-none-win_amd64.whl.

File metadata

  • Download URL: giserpy-2025.9.10-py310-none-win_amd64.whl
  • Upload date:
  • Size: 389.9 kB
  • Tags: Python 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for giserpy-2025.9.10-py310-none-win_amd64.whl
Algorithm Hash digest
SHA256 beb5ec3d48bcffe10fc9a496333a2eebf157d0dc50ab15b0f0b49664a7947c77
MD5 0b6021ddaea0cce8971ed7b6ed461b83
BLAKE2b-256 b976c5d8dfbbd84f6404bc422bcd6569c301b316b6c0ed4a8cd6cdee7dcd7a33

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py310-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py310-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 e85b0bf9d9fe167155f9eab5351d1fced4865dab2a5bdc54bf968732dce1b257
MD5 863fb96415926cb40004b7e202b1c0d3
BLAKE2b-256 95c7cc5665b7cf41bc6b2095e6c560e1e5051a0d8d5afa78882f5312f4cb25aa

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py310-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py310-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 197a5fafac54c9fc66f28a86dd6ad1c758740da0aeb1d4d9696d7e5edc17d7b9
MD5 17a14fd177fbe0f660bda2964decbeb2
BLAKE2b-256 730934f7ec6e8ba5e9d89f1b44339ab9cabc67a8895610eb420a452dc7ab79ee

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py39-none-win_amd64.whl.

File metadata

  • Download URL: giserpy-2025.9.10-py39-none-win_amd64.whl
  • Upload date:
  • Size: 390.4 kB
  • Tags: Python 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for giserpy-2025.9.10-py39-none-win_amd64.whl
Algorithm Hash digest
SHA256 ba078f98d6aaf4f2174afad052dc149e671f95187368974340099997948be8d8
MD5 45277f12fa7e59b7c1f9e7730463591d
BLAKE2b-256 47abcbfb50a2b9a5a0266fa6bbdcb6780132d21ceca04ee5c812340f216e6175

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py39-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py39-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 74cc3c3dd8f1b2b1db70c87006a4658b014acf7bb3192db5ccfa0cb3a534ea7c
MD5 9f39bded5a718fe8233990dfa702af2c
BLAKE2b-256 1b6b447d591eb4641cef0788445ece7d75ddec6df0b80cde3e5c3d2648fd1e33

See more details on using hashes here.

File details

Details for the file giserpy-2025.9.10-py39-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for giserpy-2025.9.10-py39-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 74a7525ced4e603c5a828469ba6d76732bc5523706c8aadeed4e0a65b94ae153
MD5 a5bc9c01a1a03368900f45d7e5c15dc7
BLAKE2b-256 a4b140752badbaa8b299d9dbc713ba2c5ae057fd12cae5d43b794b959a322d0a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page