location
¶
Classes:
-
Location–Represents a single location using lat/lon as a base coordinate system.
-
LocationSet–Represents a collection of location using lat/lon as a base coordinate
Location
¶
Represents a single location using lat/lon as a base coordinate system.
Examples:
If you trust my programming skills and have any of the argument types listed below::
Location.load( args, srs=SRS )
If you have a latitude and longitude value::
Location( latitude, longitude )
If you have an X and a Y coordinate in any arbitrary SRS::
Location.fromXY( X, Y, srs=SRS)
If you have a string structured like such: "(5.12243,52,11342)"::
Location.fromString( string, srs=SRS )
If you have a point geometry::
Location.fromPointGeom( pointGeometryObject )
Initialize a Location Object by explicitly providing lat/lon coordinates.
Parameters:
Methods:
-
asGeom–Extract the Location as an ogr.Geometry object in an arbitrary SRS.
-
asXY–Extract the Location as an (X,Y) tuple in an arbitrary SRS.
-
fromPointGeom–Initialize a Location Object by providing an OGR Point Object.
-
fromString–Initialize a Location Object by providing a string.
-
fromXY–Initialize a Location Object by providing a n X and Y coordinate.
-
load–Tries to load a Location object in the correct manner by inferring
-
makePickleable–Clears OGR objects from the Location's internals so that it becomes
Source code in geokit/core/location.py
asGeom
¶
asGeom(srs: srs_input = 'latlon') -> Geometry
Extract the Location as an ogr.Geometry object in an arbitrary SRS.
Parameters:
-
(srs¶Anything acceptable to gk.srs.loadSRS, default:'latlon') –The srs for the created object
Returns:
-
Geometry–
Source code in geokit/core/location.py
asXY
¶
asXY(srs) -> tuple
Extract the Location as an (X,Y) tuple in an arbitrary SRS.
Parameters:
-
(srs¶Anything acceptable to gk.srs.loadSRS) –The srs for the created tuple
Returns:
-
tuple -> (X, Y)–
Source code in geokit/core/location.py
fromPointGeom
staticmethod
¶
Initialize a Location Object by providing an OGR Point Object.
Note: Must have an SRS within the object.
Parameters:
-
(g¶Geometry) –The string to parse
Returns:
-
Locations–
Source code in geokit/core/location.py
fromString
staticmethod
¶
Initialize a Location Object by providing a string.
Notes
- Must be formatted like such: "(5.12243,52,11342)"
- Whitespace is okay
- Will only take the FIRST match it finds
Parameters:
-
(s¶string) –The string to parse
-
(srs¶Anything acceptable to gk.srs.loadSRS; optional, default:None) –The srs for input coordinates
Returns:
-
Locations–
Source code in geokit/core/location.py
fromXY
staticmethod
¶
Initialize a Location Object by providing a n X and Y coordinate.
Parameters:
-
(x¶numeric) –The location's x value
-
(y¶numeric) –The location's y value
-
(srs¶Anything acceptable to gk.srs.loadSRS) –The srs for input coordinates
Returns:
-
Locations–
Source code in geokit/core/location.py
load
staticmethod
¶
Tries to load a Location object in the correct manner by inferring from the input type.
Note: Ends up calling one of the Location.from??? initializers.
Parameters:
-
(loc¶Location or Geometry or str or tuple) –The location data to interpret
-
(srs¶Anything acceptable to gk.srs.loadSRS, default:4326) –The srs for input coordinates. If not given, latitude and longitude coordinates are expected.
Returns:
-
Locations–
Source code in geokit/core/location.py
makePickleable
¶
LocationSet
¶
Represents a collection of location using lat/lon as a base coordinate system.
Note
When initializing, an iterable of anything acceptable by Location.load is expected.
Examples:
::
LocationSet( iterable )
Initialize a LocationSet Object.
Note: If only a single location is given, a set is still created.
Parameters:
-
(locations¶iterable) –The locations to collect. Can be anything acceptable by Location.load().
-
(srs¶Anything acceptable to gk.srs.loadSRS; optional, default:4326) –The srs for input coordinates. If not given, lat/lon coordinates are expected.
Methods:
-
asGeom–Create a list of ogr.Geometry representations of all locations in the
-
asString–Create a list of string representations of all locations in the set.
-
asXY–Create an Nx2 array of x and y coordinates for all locations in the set.
-
bisect–Cluster the locations by finding a bisecting line in lat/lon
-
getBounds–Returns the bounding box of all locations in the set in an arbitrary
-
makePickleable–Clears OGR objects from all individual Location's internals so that
-
splitKMeans–Split the locations into groups according to KMEans clustering.
Source code in geokit/core/location.py
asGeom
¶
asGeom(srs=4326) -> list[Geometry]
Create a list of ogr.Geometry representations of all locations in the set.
Parameters:
-
(srs¶Anything acceptable to gk.srs.loadSRS; optional, default:4326) –The srs for output coordinates. If not given, lat/lon coordinates are expected.
Returns:
-
list -> [ Geometry1, Geometry1, ... ]–
Source code in geokit/core/location.py
asString
¶
Create a list of string representations of all locations in the set.
Returns:
-
list -> [ '(lon1,lat1)', (lon2,lat2)', ... ]–
asXY
¶
asXY(srs)
Create an Nx2 array of x and y coordinates for all locations in the set.
Parameters:
-
(srs¶Anything acceptable to gk.srs.loadSRS; optional) –The srs for output coordinates
Returns:
-
numpy.ndarray -> Nx2–
Source code in geokit/core/location.py
bisect
¶
Cluster the locations by finding a bisecting line in lat/lon coordinates in either (or both) directions.
Notes
- An equal count of locations in each group is not guaranteed
- Will always either return 2 or 4 cluster groups
Parameters:
-
(lon¶bool, default:True) –Split locations in the longitude direction
-
(lat¶bool, default:True) –Split locations in the latitude direction
Yields:
-
LocationSet -> A location set of each clustered group–
Source code in geokit/core/location.py
getBounds
¶
getBounds(srs=4326)
Returns the bounding box of all locations in the set in an arbitrary SRS.
Parameters:
-
(srs¶Anything acceptable to gk.srs.loadSRS; optional, default:4326) –The srs for output coordinates. If not given, lat/lon coordinates are expected.
Returns:
-
tuple -> (xMin, yMin, xMax, yMax)–
Source code in geokit/core/location.py
makePickleable
¶
Clears OGR objects from all individual Location's internals so that they become "pickleable".
splitKMeans
¶
splitKMeans(groups=2, **kwargs)
Split the locations into groups according to KMEans clustering.
Note: An equal count of locations in each group is not guaranteed.
Parameters:
-
(groups¶int, default:2) –The number of groups to split the locations into
-
–kwargs¶All other keyword arguments are passed on to sklearn.cluster.KMeans
Yields:
-
LocationSet -> A location set of each clustered group–