Module pygw.base.type_conversions
Source code
#
# Copyright (c) 2013-2022 Contributors to the Eclipse Foundation
#
# See the NOTICE file distributed with this work for additional information regarding copyright
# ownership. All rights reserved. This program and the accompanying materials are made available
# under the terms of the Apache License, Version 2.0 which accompanies this distribution and is
# available at http://www.apache.org/licenses/LICENSE-2.0.txt
# ===============================================================================================
from decimal import Decimal
from datetime import date, timezone
from datetime import datetime
from py4j.java_gateway import JavaClass
from shapely.geometry.base import BaseGeometry
from shapely.geometry import Point
from shapely.geometry import LineString
from shapely.geometry import Polygon
from shapely.geometry import MultiPoint
from shapely.geometry import MultiLineString
from shapely.geometry import MultiPolygon
from shapely.geometry import GeometryCollection
from shapely.wkb import dumps
from shapely.wkb import loads
from pygw.config import java_pkg
from pygw.config import java_gateway
_wkb_reader = java_pkg.org.locationtech.jts.io.WKBReader()
_wkb_writer = java_pkg.org.locationtech.jts.io.WKBWriter()
def _type_to_string(py_type):
if isinstance(py_type, tuple):
return ", ".join(t.__name__ for t in py_type)
else:
return py_type.__name__
class AttributeType:
"""
Base class for attributes that can be converted to and from Java variants.
"""
def __init__(self, binding, py_type):
self.binding = binding
self._py_type = py_type
def to_java(self, value):
"""
Convert a Python variable into its Java counterpart.
Args:
value (any): The Python variable to convert.
Returns:
The Java counterpart of the Python variable.
"""
if value is None:
return value
if isinstance(value, self._py_type):
return self._to_java(value)
else:
self._value_error(value, _type_to_string(self._py_type))
def _to_java(self, value):
return value
def from_java(self, value):
"""
Convert a Java variable into its Python counterpart.
Args:
value (any): The Java variable to convert.
Returns:
The Python counterpart of the Java variable.
"""
if value is None:
return value
else:
return self._from_java(value)
def _from_java(self, value):
return value
def _value_error(self, value, expected):
raise ValueError("Value[%s] should be of type %s." % (str(value), expected))
class ArrayAttributeType(AttributeType):
"""
Base class for attributes that represent an array of values.
"""
def __init__(self, subtype, py_type=(list, tuple)):
self.subtype = subtype
self._j_class = JavaClass(self.subtype.binding, java_gateway._gateway_client)
super().__init__("[L%s;" % self.subtype.binding, py_type)
def _to_java(self, value):
j_arr = java_gateway.new_array(self._j_class, len(value))
for i in range(len(value)):
if value[i] is None:
continue
j_arr[i] = self.subtype._to_java(value[i])
return j_arr
def _from_java(self, value):
py_array = []
for j_obj in value:
py_array.append(self.subtype.from_java(j_obj))
return py_array
class BigDecimalType(AttributeType):
"""
Conversion class for BigDecimal.
"""
def __init__(self):
super().__init__("java.math.BigDecimal", Decimal)
def _to_java(self, value):
return java_pkg.java.math.BigDecimal(str(value))
class BigDecimalArrayType(ArrayAttributeType):
"""
Conversion class for BigDecimal[].
"""
def __init__(self):
super().__init__(BigDecimalType())
class BigIntegerType(AttributeType):
"""
Conversion class for BigInteger.
"""
def __init__(self):
super().__init__("java.math.BigInteger", int)
def _to_java(self, value):
return java_pkg.java.math.BigInteger(str(value))
def _from_java(self, value):
return int(value.toString())
class BigIntegerArrayType(ArrayAttributeType):
"""
Conversion class for BigInteger[].
"""
def __init__(self):
super().__init__(BigIntegerType())
class BooleanType(AttributeType):
"""
Conversion class for Boolean.
"""
def __init__(self):
super().__init__("java.lang.Boolean", bool)
class BooleanArrayType(ArrayAttributeType):
"""
Conversion class for Boolean[].
"""
def __init__(self):
super().__init__(BooleanType())
class FloatType(AttributeType):
"""
Conversion class for Float.
"""
def __init__(self):
super().__init__("java.lang.Float", (int, float))
def _to_java(self, value):
return value * 1.0
class FloatArrayType(ArrayAttributeType):
"""
Conversion class for Float[].
"""
def __init__(self):
super().__init__(FloatType())
class DoubleType(AttributeType):
"""
Conversion class for Double.
"""
def __init__(self):
super().__init__("java.lang.Double", (int, float))
def _to_java(self, value):
return value * 1.0
class DoubleArrayType(ArrayAttributeType):
"""
Conversion class for Double[].
"""
def __init__(self):
super().__init__(DoubleType())
class ByteType(AttributeType):
"""
Conversion class for Byte.
"""
def __init__(self):
super().__init__("java.lang.Byte", int)
class ByteArrayType(ArrayAttributeType):
"""
Conversion class for Byte[].
"""
def __init__(self):
super().__init__(ByteType(), (list, bytes))
def _from_java(self, value):
if None in value:
return super()._from_java(value)
return bytes(super()._from_java(value))
class ShortType(AttributeType):
"""
Conversion class for Short.
"""
def __init__(self):
super().__init__("java.lang.Short", int)
class ShortArrayType(ArrayAttributeType):
"""
Conversion class for Short[].
"""
def __init__(self):
super().__init__(ShortType())
class IntegerType(AttributeType):
"""
Conversion class for Integer.
"""
def __init__(self):
super().__init__("java.lang.Integer", int)
class IntegerArrayType(ArrayAttributeType):
"""
Conversion class for Integer[].
"""
def __init__(self):
super().__init__(IntegerType())
class LongType(AttributeType):
"""
Conversion class for Long.
"""
def __init__(self):
super().__init__("java.lang.Long", int)
class LongArrayType(ArrayAttributeType):
"""
Conversion class for Long[].
"""
def __init__(self):
super().__init__(LongType())
class PrimitiveArrayType(AttributeType):
"""
Base class for arrays made up of Java primitives.
"""
def __init__(self, binding, j_class, py_element_type, py_type=list):
super().__init__(binding, py_type)
self._j_class = j_class
self._py_element_type = py_element_type
def _to_java(self, value):
j_arr = self._build_array(value)
for i in range(len(value)):
if value[i] is None:
raise ValueError("Value at index %d should not be None for primitive array." % i)
if isinstance(value[i], self._py_element_type):
j_arr[i] = self._value_to_java(value[i])
else:
self._value_error(value[i], _type_to_string(self._py_element_type))
return j_arr
def _from_java(self, value):
py_array = []
for j_obj in value:
py_array.append(self._value_from_java(j_obj))
return py_array
def _build_array(self, value):
return java_gateway.new_array(self._j_class, len(value))
def _value_to_java(self, value):
return value
def _value_from_java(self, value):
return value
class PrimitiveBooleanArrayType(PrimitiveArrayType):
"""
Conversion class for boolean[].
"""
def __init__(self):
super().__init__("[Z", java_gateway.jvm.boolean, bool)
class PrimitiveFloatArrayType(PrimitiveArrayType):
"""
Conversion class for float[].
"""
def __init__(self):
super().__init__("[F", java_gateway.jvm.float, (int, float))
def _value_to_java(self, value):
return value * 1.0
class PrimitiveDoubleArrayType(PrimitiveArrayType):
"""
Conversion class for double[].
"""
def __init__(self):
super().__init__("[D", java_gateway.jvm.double, (int, float))
def _value_to_java(self, value):
return value * 1.0
class PrimitiveByteArrayType(PrimitiveArrayType):
"""
Conversion class for byte[].
"""
def __init__(self):
super().__init__("[B", java_gateway.jvm.byte, int, (list, bytes))
def _to_java(self, value):
if isinstance(value, bytes):
return value
return bytes(super()._to_java(value))
def _from_java(self, value):
if isinstance(value, bytes):
return value
return bytes(super()._from_java(value))
def _value_to_java(self, value):
return value % 256
def _build_array(self, value):
return bytearray(super()._build_array(value))
class PrimitiveShortArrayType(PrimitiveArrayType):
"""
Conversion class for short[].
"""
def __init__(self):
super().__init__("[S", java_gateway.jvm.short, int)
class PrimitiveIntArrayType(PrimitiveArrayType):
"""
Conversion class for int[].
"""
def __init__(self):
super().__init__("[I", java_gateway.jvm.int, int)
class PrimitiveLongArrayType(PrimitiveArrayType):
"""
Conversion class for long[].
"""
def __init__(self):
super().__init__("[J", java_gateway.jvm.long, int)
class StringType(AttributeType):
"""
Conversion class for String.
"""
def __init__(self):
super().__init__("java.lang.String", str)
class StringArrayType(ArrayAttributeType):
"""
Conversion class for String[].
"""
def __init__(self):
super().__init__(StringType())
class DateType(AttributeType):
"""
Conversion class for Date.
"""
def __init__(self):
super().__init__("java.util.Date", date)
def _to_java(self, value):
return java_pkg.java.util.Date(int(value.replace(tzinfo=timezone.utc).timestamp() * 1000))
def _from_java(self, value):
return datetime.utcfromtimestamp(value.getTime() / 1000)
class DateArrayType(ArrayAttributeType):
"""
Conversion class for Date[].
"""
def __init__(self):
super().__init__(DateType())
class CalendarType(AttributeType):
"""
Conversion class for Calendar.
"""
def __init__(self):
super().__init__("java.util.Calendar", date)
self._date_type = DateType()
def _to_java(self, value):
j_timezone = java_pkg.java.util.TimeZone.getTimeZone("GMT")
j_calendar = java_pkg.java.util.Calendar.getInstance(j_timezone)
j_calendar.setTime(self._date_type._to_java(value))
return j_calendar
def _from_java(self, value):
return self._date_type._from_java(value.getTime())
class CalendarArrayType(ArrayAttributeType):
"""
Conversion class for Calendar[].
"""
def __init__(self):
super().__init__(CalendarType())
class BaseGeometryType(AttributeType):
"""
Base type for conversion between shapely geometries and JTS geometries.
"""
def __init__(self, binding, py_type):
super().__init__(binding, py_type)
def _to_java(self, value):
wkb = dumps(value)
return _wkb_reader.read(wkb)
def _from_java(self, value):
wkb = _wkb_writer.write(value)
return loads(wkb)
class PointType(BaseGeometryType):
"""
Conversion class for Point.
"""
def __init__(self):
super().__init__("org.locationtech.jts.geom.Point", Point)
class PointArrayType(ArrayAttributeType):
"""
Conversion class for Point[].
"""
def __init__(self):
super().__init__(PointType())
class MultiPointType(BaseGeometryType):
"""
Conversion class for MultiPoint.
"""
def __init__(self):
super().__init__("org.locationtech.jts.geom.MultiPoint", MultiPoint)
class MultiPointArrayType(ArrayAttributeType):
"""
Conversion class for MultiPoint[].
"""
def __init__(self):
super().__init__(MultiPointType())
class LineStringType(BaseGeometryType):
"""
Conversion class for LineString.
"""
def __init__(self):
super().__init__("org.locationtech.jts.geom.LineString", LineString)
class LineStringArrayType(ArrayAttributeType):
"""
Conversion class for LineString[].
"""
def __init__(self):
super().__init__(LineStringType())
class MultiLineStringType(BaseGeometryType):
"""
Conversion class for MultiLineString.
"""
def __init__(self):
super().__init__("org.locationtech.jts.geom.MultiLineString", MultiLineString)
class MultiLineStringArrayType(ArrayAttributeType):
"""
Conversion class for MultiLineString[].
"""
def __init__(self):
super().__init__(MultiLineStringType())
class PolygonType(BaseGeometryType):
"""
Conversion class for Polygon.
"""
def __init__(self):
super().__init__("org.locationtech.jts.geom.Polygon", Polygon)
class PolygonArrayType(ArrayAttributeType):
"""
Conversion class for Polygon[].
"""
def __init__(self):
super().__init__(PolygonType())
class MultiPolygonType(BaseGeometryType):
"""
Conversion class for MultiPolygon.
"""
def __init__(self):
super().__init__("org.locationtech.jts.geom.MultiPolygon", MultiPolygon)
class MultiPolygonArrayType(ArrayAttributeType):
"""
Conversion class for MultiPolygon[].
"""
def __init__(self):
super().__init__(MultiPolygonType())
class GeometryCollectionType(BaseGeometryType):
"""
Conversion class for GeometryCollection.
"""
def __init__(self):
super().__init__("org.locationtech.jts.geom.GeometryCollection", GeometryCollection)
class GeometryCollectionArrayType(ArrayAttributeType):
"""
Conversion class for GeometryCollection[].
"""
def __init__(self):
super().__init__(GeometryCollectionType())
class GeometryType(BaseGeometryType):
"""
Conversion class for Geometry.
"""
def __init__(self):
super().__init__("org.locationtech.jts.geom.Geometry", BaseGeometry)
class GeometryArrayType(ArrayAttributeType):
"""
Conversion class for Geometry[].
"""
def __init__(self):
super().__init__(GeometryType())
Classes
class ArrayAttributeType (subtype, py_type=(
, )) -
Base class for attributes that represent an array of values.
Source code
class ArrayAttributeType(AttributeType): """ Base class for attributes that represent an array of values. """ def __init__(self, subtype, py_type=(list, tuple)): self.subtype = subtype self._j_class = JavaClass(self.subtype.binding, java_gateway._gateway_client) super().__init__("[L%s;" % self.subtype.binding, py_type) def _to_java(self, value): j_arr = java_gateway.new_array(self._j_class, len(value)) for i in range(len(value)): if value[i] is None: continue j_arr[i] = self.subtype._to_java(value[i]) return j_arr def _from_java(self, value): py_array = [] for j_obj in value: py_array.append(self.subtype.from_java(j_obj)) return py_array
Ancestors
Subclasses
- BigDecimalArrayType
- BigIntegerArrayType
- BooleanArrayType
- FloatArrayType
- DoubleArrayType
- ByteArrayType
- ShortArrayType
- IntegerArrayType
- LongArrayType
- StringArrayType
- DateArrayType
- CalendarArrayType
- PointArrayType
- MultiPointArrayType
- LineStringArrayType
- MultiLineStringArrayType
- PolygonArrayType
- MultiPolygonArrayType
- GeometryCollectionArrayType
- GeometryArrayType
Inherited members
class AttributeType (binding, py_type)
-
Base class for attributes that can be converted to and from Java variants.
Source code
class AttributeType: """ Base class for attributes that can be converted to and from Java variants. """ def __init__(self, binding, py_type): self.binding = binding self._py_type = py_type def to_java(self, value): """ Convert a Python variable into its Java counterpart. Args: value (any): The Python variable to convert. Returns: The Java counterpart of the Python variable. """ if value is None: return value if isinstance(value, self._py_type): return self._to_java(value) else: self._value_error(value, _type_to_string(self._py_type)) def _to_java(self, value): return value def from_java(self, value): """ Convert a Java variable into its Python counterpart. Args: value (any): The Java variable to convert. Returns: The Python counterpart of the Java variable. """ if value is None: return value else: return self._from_java(value) def _from_java(self, value): return value def _value_error(self, value, expected): raise ValueError("Value[%s] should be of type %s." % (str(value), expected))
Subclasses
- ArrayAttributeType
- BigDecimalType
- BigIntegerType
- BooleanType
- FloatType
- DoubleType
- ByteType
- ShortType
- IntegerType
- LongType
- PrimitiveArrayType
- StringType
- DateType
- CalendarType
- BaseGeometryType
Methods
def from_java(self, value)
-
Convert a Java variable into its Python counterpart.
Args
value
:any
- The Java variable to convert.
Returns
The Python counterpart of the Java variable.
Source code
def from_java(self, value): """ Convert a Java variable into its Python counterpart. Args: value (any): The Java variable to convert. Returns: The Python counterpart of the Java variable. """ if value is None: return value else: return self._from_java(value)
def to_java(self, value)
-
Convert a Python variable into its Java counterpart.
Args
value
:any
- The Python variable to convert.
Returns
The Java counterpart of the Python variable.
Source code
def to_java(self, value): """ Convert a Python variable into its Java counterpart. Args: value (any): The Python variable to convert. Returns: The Java counterpart of the Python variable. """ if value is None: return value if isinstance(value, self._py_type): return self._to_java(value) else: self._value_error(value, _type_to_string(self._py_type))
class BaseGeometryType (binding, py_type)
-
Base type for conversion between shapely geometries and JTS geometries.
Source code
class BaseGeometryType(AttributeType): """ Base type for conversion between shapely geometries and JTS geometries. """ def __init__(self, binding, py_type): super().__init__(binding, py_type) def _to_java(self, value): wkb = dumps(value) return _wkb_reader.read(wkb) def _from_java(self, value): wkb = _wkb_writer.write(value) return loads(wkb)
Ancestors
Subclasses
- PointType
- MultiPointType
- LineStringType
- MultiLineStringType
- PolygonType
- MultiPolygonType
- GeometryCollectionType
- GeometryType
Inherited members
class BigDecimalArrayType
-
Conversion class for BigDecimal[].
Source code
class BigDecimalArrayType(ArrayAttributeType): """ Conversion class for BigDecimal[]. """ def __init__(self): super().__init__(BigDecimalType())
Ancestors
Inherited members
class BigDecimalType
-
Conversion class for BigDecimal.
Source code
class BigDecimalType(AttributeType): """ Conversion class for BigDecimal. """ def __init__(self): super().__init__("java.math.BigDecimal", Decimal) def _to_java(self, value): return java_pkg.java.math.BigDecimal(str(value))
Ancestors
Inherited members
class BigIntegerArrayType
-
Conversion class for BigInteger[].
Source code
class BigIntegerArrayType(ArrayAttributeType): """ Conversion class for BigInteger[]. """ def __init__(self): super().__init__(BigIntegerType())
Ancestors
Inherited members
class BigIntegerType
-
Conversion class for BigInteger.
Source code
class BigIntegerType(AttributeType): """ Conversion class for BigInteger. """ def __init__(self): super().__init__("java.math.BigInteger", int) def _to_java(self, value): return java_pkg.java.math.BigInteger(str(value)) def _from_java(self, value): return int(value.toString())
Ancestors
Inherited members
class BooleanArrayType
-
Conversion class for Boolean[].
Source code
class BooleanArrayType(ArrayAttributeType): """ Conversion class for Boolean[]. """ def __init__(self): super().__init__(BooleanType())
Ancestors
Inherited members
class BooleanType
-
Conversion class for Boolean.
Source code
class BooleanType(AttributeType): """ Conversion class for Boolean. """ def __init__(self): super().__init__("java.lang.Boolean", bool)
Ancestors
Inherited members
class ByteArrayType
-
Conversion class for Byte[].
Source code
class ByteArrayType(ArrayAttributeType): """ Conversion class for Byte[]. """ def __init__(self): super().__init__(ByteType(), (list, bytes)) def _from_java(self, value): if None in value: return super()._from_java(value) return bytes(super()._from_java(value))
Ancestors
Inherited members
class ByteType
-
Conversion class for Byte.
Source code
class ByteType(AttributeType): """ Conversion class for Byte. """ def __init__(self): super().__init__("java.lang.Byte", int)
Ancestors
Inherited members
class CalendarArrayType
-
Conversion class for Calendar[].
Source code
class CalendarArrayType(ArrayAttributeType): """ Conversion class for Calendar[]. """ def __init__(self): super().__init__(CalendarType())
Ancestors
Inherited members
class CalendarType
-
Conversion class for Calendar.
Source code
class CalendarType(AttributeType): """ Conversion class for Calendar. """ def __init__(self): super().__init__("java.util.Calendar", date) self._date_type = DateType() def _to_java(self, value): j_timezone = java_pkg.java.util.TimeZone.getTimeZone("GMT") j_calendar = java_pkg.java.util.Calendar.getInstance(j_timezone) j_calendar.setTime(self._date_type._to_java(value)) return j_calendar def _from_java(self, value): return self._date_type._from_java(value.getTime())
Ancestors
Inherited members
class DateArrayType
-
Conversion class for Date[].
Source code
class DateArrayType(ArrayAttributeType): """ Conversion class for Date[]. """ def __init__(self): super().__init__(DateType())
Ancestors
Inherited members
class DateType
-
Conversion class for Date.
Source code
class DateType(AttributeType): """ Conversion class for Date. """ def __init__(self): super().__init__("java.util.Date", date) def _to_java(self, value): return java_pkg.java.util.Date(int(value.replace(tzinfo=timezone.utc).timestamp() * 1000)) def _from_java(self, value): return datetime.utcfromtimestamp(value.getTime() / 1000)
Ancestors
Inherited members
class DoubleArrayType
-
Conversion class for Double[].
Source code
class DoubleArrayType(ArrayAttributeType): """ Conversion class for Double[]. """ def __init__(self): super().__init__(DoubleType())
Ancestors
Inherited members
class DoubleType
-
Conversion class for Double.
Source code
class DoubleType(AttributeType): """ Conversion class for Double. """ def __init__(self): super().__init__("java.lang.Double", (int, float)) def _to_java(self, value): return value * 1.0
Ancestors
Inherited members
class FloatArrayType
-
Conversion class for Float[].
Source code
class FloatArrayType(ArrayAttributeType): """ Conversion class for Float[]. """ def __init__(self): super().__init__(FloatType())
Ancestors
Inherited members
class FloatType
-
Conversion class for Float.
Source code
class FloatType(AttributeType): """ Conversion class for Float. """ def __init__(self): super().__init__("java.lang.Float", (int, float)) def _to_java(self, value): return value * 1.0
Ancestors
Inherited members
class GeometryArrayType
-
Conversion class for Geometry[].
Source code
class GeometryArrayType(ArrayAttributeType): """ Conversion class for Geometry[]. """ def __init__(self): super().__init__(GeometryType())
Ancestors
Inherited members
class GeometryCollectionArrayType
-
Conversion class for GeometryCollection[].
Source code
class GeometryCollectionArrayType(ArrayAttributeType): """ Conversion class for GeometryCollection[]. """ def __init__(self): super().__init__(GeometryCollectionType())
Ancestors
Inherited members
class GeometryCollectionType
-
Conversion class for GeometryCollection.
Source code
class GeometryCollectionType(BaseGeometryType): """ Conversion class for GeometryCollection. """ def __init__(self): super().__init__("org.locationtech.jts.geom.GeometryCollection", GeometryCollection)
Ancestors
Inherited members
class GeometryType
-
Conversion class for Geometry.
Source code
class GeometryType(BaseGeometryType): """ Conversion class for Geometry. """ def __init__(self): super().__init__("org.locationtech.jts.geom.Geometry", BaseGeometry)
Ancestors
Inherited members
class IntegerArrayType
-
Conversion class for Integer[].
Source code
class IntegerArrayType(ArrayAttributeType): """ Conversion class for Integer[]. """ def __init__(self): super().__init__(IntegerType())
Ancestors
Inherited members
class IntegerType
-
Conversion class for Integer.
Source code
class IntegerType(AttributeType): """ Conversion class for Integer. """ def __init__(self): super().__init__("java.lang.Integer", int)
Ancestors
Inherited members
class LineStringArrayType
-
Conversion class for LineString[].
Source code
class LineStringArrayType(ArrayAttributeType): """ Conversion class for LineString[]. """ def __init__(self): super().__init__(LineStringType())
Ancestors
Inherited members
class LineStringType
-
Conversion class for LineString.
Source code
class LineStringType(BaseGeometryType): """ Conversion class for LineString. """ def __init__(self): super().__init__("org.locationtech.jts.geom.LineString", LineString)
Ancestors
Inherited members
class LongArrayType
-
Conversion class for Long[].
Source code
class LongArrayType(ArrayAttributeType): """ Conversion class for Long[]. """ def __init__(self): super().__init__(LongType())
Ancestors
Inherited members
class LongType
-
Conversion class for Long.
Source code
class LongType(AttributeType): """ Conversion class for Long. """ def __init__(self): super().__init__("java.lang.Long", int)
Ancestors
Inherited members
class MultiLineStringArrayType
-
Conversion class for MultiLineString[].
Source code
class MultiLineStringArrayType(ArrayAttributeType): """ Conversion class for MultiLineString[]. """ def __init__(self): super().__init__(MultiLineStringType())
Ancestors
Inherited members
class MultiLineStringType
-
Conversion class for MultiLineString.
Source code
class MultiLineStringType(BaseGeometryType): """ Conversion class for MultiLineString. """ def __init__(self): super().__init__("org.locationtech.jts.geom.MultiLineString", MultiLineString)
Ancestors
Inherited members
class MultiPointArrayType
-
Conversion class for MultiPoint[].
Source code
class MultiPointArrayType(ArrayAttributeType): """ Conversion class for MultiPoint[]. """ def __init__(self): super().__init__(MultiPointType())
Ancestors
Inherited members
class MultiPointType
-
Conversion class for MultiPoint.
Source code
class MultiPointType(BaseGeometryType): """ Conversion class for MultiPoint. """ def __init__(self): super().__init__("org.locationtech.jts.geom.MultiPoint", MultiPoint)
Ancestors
Inherited members
class MultiPolygonArrayType
-
Conversion class for MultiPolygon[].
Source code
class MultiPolygonArrayType(ArrayAttributeType): """ Conversion class for MultiPolygon[]. """ def __init__(self): super().__init__(MultiPolygonType())
Ancestors
Inherited members
class MultiPolygonType
-
Conversion class for MultiPolygon.
Source code
class MultiPolygonType(BaseGeometryType): """ Conversion class for MultiPolygon. """ def __init__(self): super().__init__("org.locationtech.jts.geom.MultiPolygon", MultiPolygon)
Ancestors
Inherited members
class PointArrayType
-
Conversion class for Point[].
Source code
class PointArrayType(ArrayAttributeType): """ Conversion class for Point[]. """ def __init__(self): super().__init__(PointType())
Ancestors
Inherited members
class PointType
-
Conversion class for Point.
Source code
class PointType(BaseGeometryType): """ Conversion class for Point. """ def __init__(self): super().__init__("org.locationtech.jts.geom.Point", Point)
Ancestors
Inherited members
class PolygonArrayType
-
Conversion class for Polygon[].
Source code
class PolygonArrayType(ArrayAttributeType): """ Conversion class for Polygon[]. """ def __init__(self): super().__init__(PolygonType())
Ancestors
Inherited members
class PolygonType
-
Conversion class for Polygon.
Source code
class PolygonType(BaseGeometryType): """ Conversion class for Polygon. """ def __init__(self): super().__init__("org.locationtech.jts.geom.Polygon", Polygon)
Ancestors
Inherited members
class PrimitiveArrayType (binding, j_class, py_element_type, py_type=
) -
Base class for arrays made up of Java primitives.
Source code
class PrimitiveArrayType(AttributeType): """ Base class for arrays made up of Java primitives. """ def __init__(self, binding, j_class, py_element_type, py_type=list): super().__init__(binding, py_type) self._j_class = j_class self._py_element_type = py_element_type def _to_java(self, value): j_arr = self._build_array(value) for i in range(len(value)): if value[i] is None: raise ValueError("Value at index %d should not be None for primitive array." % i) if isinstance(value[i], self._py_element_type): j_arr[i] = self._value_to_java(value[i]) else: self._value_error(value[i], _type_to_string(self._py_element_type)) return j_arr def _from_java(self, value): py_array = [] for j_obj in value: py_array.append(self._value_from_java(j_obj)) return py_array def _build_array(self, value): return java_gateway.new_array(self._j_class, len(value)) def _value_to_java(self, value): return value def _value_from_java(self, value): return value
Ancestors
Subclasses
- PrimitiveBooleanArrayType
- PrimitiveFloatArrayType
- PrimitiveDoubleArrayType
- PrimitiveByteArrayType
- PrimitiveShortArrayType
- PrimitiveIntArrayType
- PrimitiveLongArrayType
Inherited members
class PrimitiveBooleanArrayType
-
Conversion class for boolean[].
Source code
class PrimitiveBooleanArrayType(PrimitiveArrayType): """ Conversion class for boolean[]. """ def __init__(self): super().__init__("[Z", java_gateway.jvm.boolean, bool)
Ancestors
Inherited members
class PrimitiveByteArrayType
-
Conversion class for byte[].
Source code
class PrimitiveByteArrayType(PrimitiveArrayType): """ Conversion class for byte[]. """ def __init__(self): super().__init__("[B", java_gateway.jvm.byte, int, (list, bytes)) def _to_java(self, value): if isinstance(value, bytes): return value return bytes(super()._to_java(value)) def _from_java(self, value): if isinstance(value, bytes): return value return bytes(super()._from_java(value)) def _value_to_java(self, value): return value % 256 def _build_array(self, value): return bytearray(super()._build_array(value))
Ancestors
Inherited members
class PrimitiveDoubleArrayType
-
Conversion class for double[].
Source code
class PrimitiveDoubleArrayType(PrimitiveArrayType): """ Conversion class for double[]. """ def __init__(self): super().__init__("[D", java_gateway.jvm.double, (int, float)) def _value_to_java(self, value): return value * 1.0
Ancestors
Inherited members
class PrimitiveFloatArrayType
-
Conversion class for float[].
Source code
class PrimitiveFloatArrayType(PrimitiveArrayType): """ Conversion class for float[]. """ def __init__(self): super().__init__("[F", java_gateway.jvm.float, (int, float)) def _value_to_java(self, value): return value * 1.0
Ancestors
Inherited members
class PrimitiveIntArrayType
-
Conversion class for int[].
Source code
class PrimitiveIntArrayType(PrimitiveArrayType): """ Conversion class for int[]. """ def __init__(self): super().__init__("[I", java_gateway.jvm.int, int)
Ancestors
Inherited members
class PrimitiveLongArrayType
-
Conversion class for long[].
Source code
class PrimitiveLongArrayType(PrimitiveArrayType): """ Conversion class for long[]. """ def __init__(self): super().__init__("[J", java_gateway.jvm.long, int)
Ancestors
Inherited members
class PrimitiveShortArrayType
-
Conversion class for short[].
Source code
class PrimitiveShortArrayType(PrimitiveArrayType): """ Conversion class for short[]. """ def __init__(self): super().__init__("[S", java_gateway.jvm.short, int)
Ancestors
Inherited members
class ShortArrayType
-
Conversion class for Short[].
Source code
class ShortArrayType(ArrayAttributeType): """ Conversion class for Short[]. """ def __init__(self): super().__init__(ShortType())
Ancestors
Inherited members
class ShortType
-
Conversion class for Short.
Source code
class ShortType(AttributeType): """ Conversion class for Short. """ def __init__(self): super().__init__("java.lang.Short", int)
Ancestors
Inherited members
class StringArrayType
-
Conversion class for String[].
Source code
class StringArrayType(ArrayAttributeType): """ Conversion class for String[]. """ def __init__(self): super().__init__(StringType())
Ancestors
Inherited members
class StringType
-
Conversion class for String.
Source code
class StringType(AttributeType): """ Conversion class for String. """ def __init__(self): super().__init__("java.lang.String", str)
Ancestors
Inherited members