Main Module¶
In this tutorial, the core functions of mygeopackage will be demonstrated.
Read data from geojson¶
In [1]:
from mygeopackage import Geo
geojson = Geo(r'https://github.com/yungming0119/mygeopackage/blob/main/docs/notebooks/data/sample_points.geojson?raw=true',file_type='geojson',request=True)
Notice in this demo, two additional arguments are added to the instantiate function of Geo class. file_type determines what format of GIS data will be loaded. Default is set to 'geojson' for file_type. When request is set to False, geojson will be loaded from local file system.
Access data attributes¶
In [2]:
geojson.crs
Out[2]:
'urn:ogc:def:crs:OGC:1.3:CRS84'
In [3]:
geojson.attributes
Out[3]:
['FID', 'NCESSCH', 'LEAID', 'NAME', 'OPSTFIPS', 'STREET', 'CITY', 'STATE', 'ZIP', 'STFIP', 'CNTY', 'NMCNTY', 'LOCALE', 'LAT', 'LON', 'CBSA', 'NMCBSA', 'CBSATYPE', 'CSA', 'NMCSA', 'NECTA', 'NMNECTA', 'CD', 'SLDL', 'SLDU', 'SCHOOLYEAR']
In [4]:
geojson.data
Out[4]:
array([['-86.20617875299996', '34.260200473000054', '1', ..., '01026', '01009', '2018-2019'], ['-86.20488875199999', '34.26223247300004', '2', ..., '01026', '01009', '2018-2019'], ['-86.22014875799994', '34.27332447500004', '3', ..., '01026', '01009', '2018-2019'], ..., ['-64.89902190199996', '18.354784900000027', '102174', ..., 'N', 'N', '2018-2019'], ['-64.94593791699998', '18.336660895000023', '102175', ..., 'N', 'N', '2018-2019'], ['-64.89030889899993', '18.318232890000047', '102176', ..., 'N', 'N', '2018-2019']], dtype='<U60')
The Geo object has three attributes: crs, attributes, data. crs is the coordinate reference system. attributes is a list of the field names for attribute data. data is a numpy array for geometry and attribute value. For point data, X and Y coordinate will be at column 0 and 1.
Read data from shapefile¶
In [5]:
shp = Geo(r'./data/sample_points.shp',file_type='shp')
By specifying file_type to 'shp', we can read local shapefile and convert it to a numpy array.
Last update: 2021-05-03