Class Geometry
- java.lang.Object
-
- com.supermap.data.Geometry
-
- Direct Known Subclasses:
- GeoArc, GeoBSpline, GeoCardinal, GeoChord, GeoCircle, GeoCompound, GeoCurve, GeoEllipse, GeoEllipticArc, GeoGraphicObject, GeoLine, GeoLineM, Geometry3D, GeoPie, GeoPoint, GeoRectangle, GeoRegion, GeoText
public abstract class Geometry extends java.lang.Object
The base class of all the specific geometry class (GeoPoint
,GeoLine
,GeoRegion
) provide the basic methods for the geometry classes.This class is used to represent the spatial characters of the 3D geographic entity, it provides the related processing methods. Use
GeoPoint
,GeoLine
andGeoRegion
to describe different geographic entities. When disposed the subobject of the object, call the method of this class to throw the ObjectDisposedException.The
Geometry
objects created by the user, such asGeoPoint
,GeoLine
,GeoRegion
, etc. It needs to be released if not needed any more.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description abstract Geometry
clone()
Returns a copy of the current object.void
dispose()
Release the resource occupy by this object.boolean
fromGeoJSON(java.lang.String geoJSON)
Acquire Geometry from GeoJSON format string.boolean
fromXML(java.lang.String xml)
Loading geometry objects from XML.Rectangle2D
getBounds()
Returns the enclosing rectangle of the geometry object.int
getID()
Returns the identifier of the geometry.Point2D
getInnerPoint()
Returns the inner point of the geometry object.GeoStyle
getStyle()
Returns the GeoStyle of the geometry objectis.GeometryType
getType()
Returns the type of the geometry object.boolean
hitTest(Point2D point, double tolerance)
Tests in the given tolerence, whether the given point is in the geometry object.boolean
isEmpty()
Determines whether the geometry object is null.void
offset(double dx, double dy)
Moves this Geometry by a specified amount.void
resize(Rectangle2D bounds)
Resizes the Geometry object to let the bounds equal the specified Rectangle2D.void
rotate(Point2D basePoint, double angle)
Rotate the geometry object by specific degree with the specific base point, anticlockwise is the positive direction, in degree.void
setEmpty()
Clears the spatial data from this geometric object., whereas styles and ID of this geometric object remains unchanged.void
setStyle(GeoStyle value)
Sets the GeoStyle of the geometry object.java.lang.String
toGeoJSON()
Converts Geometry into GeoJSON format string.java.lang.String
toXML()
Returns the XML string of the geometric object
-
-
-
Method Detail
-
getBounds
public Rectangle2D getBounds()
Returns the enclosing rectangle of the geometry object. When the minimum minimum bounding box of a point object shrinks to a point, the coordinate value of the left boundary of the rectangle equals to the coordinate value of the right boundary of the rectangle, the coordinate value of the top boundary equals to the bottom boundary. They are the x and y coordinates of the point respectively.- Returns:
- A
Rectangle2D
object represent the enclosing rectangle of the geometry object. - See Also:
Rectangle2D
- Default:
- The default value is Rectangle2D(0,0,0,0).
-
getInnerPoint
public Point2D getInnerPoint()
Returns the inner point of the geometry object.- The inner point of a Point object is the point itself;
- The inner point of a Line object is the middle vertex of the first part of the Line objects, if the number of the vertices of the part is even(the number of the vertices is more than two), the posterior one of the two middle vertices will be the inner point, if the number of the vertices of the part is two, the center of the two vertices will be the inner point;
- The inner point of a Region object is inside the geometric object and close to the center point;
- The inner point of a Text object is the anchor point of the first part of the Text object.
The inner point can be used in various situations.
- Returns:
- The inner point of the Geometry object.
- Default:
- The default value is Point2D( 0.0).
-
getID
public int getID()
Returns the identifier of the geometry.- Returns:
- The identifier of the geometry.
- Default:
- The default value is zero.
-
isEmpty
public boolean isEmpty()
Determines whether the geometry object is null.- Returns:
- a boolean, whether the geometry object is null.
- Default:
- True if the geometric object is null; otherwise, false. The default value is true.
-
getStyle
public GeoStyle getStyle()
Returns the GeoStyle of the geometry objectis. GeoStyle is used to define symbols, line styles, fill modes and other information of the geometry object.- Returns:
- The style of the geometry object.
- Default:
- The default value is null.
-
setStyle
public void setStyle(GeoStyle value)
Sets the GeoStyle of the geometry object. GeoStyle is used to define symbols, line styles, fill modes and other information of the geometry object.- Parameters:
value
- TheGeoStyle
object to set the style of the geometry object.
-
getType
public GeometryType getType()
Returns the type of the geometry object. The returned value is the constant defined by theGeometryType
class, see theGeometryType
class.- Returns:
- The type of the geometry object.
- See Also:
GeometryType
-
clone
public abstract Geometry clone()
Returns a copy of the current object.- Overrides:
clone
in classjava.lang.Object
- Returns:
- Gets a new geometry object by clone.
-
hitTest
public boolean hitTest(Point2D point, double tolerance)
Tests in the given tolerence, whether the given point is in the geometry object.Tests whether current geometric object has the intersection with the circle that is drawn with the specified Point2D as the center and the specified tolerance as the radius. If the geometric intersects the circle with the specified center and radius, True will be returned; Otherwise, False will be returned.
- Parameters:
point
- Test Pointstolerance
- A tolerance value and the unit is the same as that of the dataset.- Returns:
- the test result, return true if clicked on the geometry.Otherwise,false.
- See Also:
Point2D
-
offset
public void offset(double dx, double dy)
Moves this Geometry by a specified amount.The figure below shows the result of offsetting a GeoRegion object.
- Parameters:
dx
- The amount to offset the x-coordinate.dy
- The amount to offset the y-coordinate.- Example:
- The following example demonstrates how to perform offset, mirror and other operations on it.
public void offsetTest() { // Suppose you open a workspace object workspace, and there is a datasource object in the workspace. // Get a dataset from the datasource // Get the record that the values of SmID equals to 53, and return the corresponding geometric objects DatasetVector dataset = (DatasetVector) datasource.getDatasets().get( "World"); Recordset recordset = dataset.query("SmID=53", CursorType.STATIC); Geometry geometry = recordset.getGeometry(); // Determines wether the geometric object is empty, if it is not empty, reconstructing geometric objects, setting styles, translating, symmetry, rotating, and zooming geometric objects. if (!geometry.isEmpty()) { geometry.fromXML(geometry.toXML()); geometry.setStyle(new GeoStyle()); geometry.offset(100, 100); Rectangle2D rectangle2D = geometry.getBounds(); geometry.mirror(geometry.getInnerPoint(), new Point2D(rectangle2D .getBottom(), rectangle2D.getRight())); geometry.rotate(geometry.getInnerPoint(), 30); geometry.resize(new Rectangle2D(0, 0, 1024, 1024)); } // Release resources recordset.dispose(); dataset.close(); geometry.dispose(); }
-
resize
public void resize(Rectangle2D bounds)
Resizes the Geometry object to let the bounds equal the specified Rectangle2D.For geometry point, this method only change it location and move it to the center point of the given rectangle; for text object, this method will change the text size.
Change the size of the geometry, overturn the object horizontally if the width is an negative value, overturn the object vertically is the height is an negative value.
Below is the zooming effects of region objects.
Throw an exception ArgumentInvalid if the area of the rectangle passed in is 0.
- Parameters:
bounds
- The extent of the geometry after adjust the size.- Throws:
ArgumentInvalid
- if the area of bounds is 0.
-
rotate
public void rotate(Point2D basePoint, double angle)
Rotate the geometry object by specific degree with the specific base point, anticlockwise is the positive direction, in degree.
The example below rotates a GeoRegion object 90 degrees anticlockwise round the specified base point.
- Parameters:
basePoint
- The base point of rotationangle
- The angle of rotation
-
setEmpty
public void setEmpty()
Clears the spatial data from this geometric object., whereas styles and ID of this geometric object remains unchanged.
-
dispose
public void dispose()
Release the resource occupy by this object.
-
toGeoJSON
public java.lang.String toGeoJSON()
Converts Geometry into GeoJSON format string. The specific implementation is finished by the subclass.The supported types are GeoPoint, GeoLine, GeoRegion, line or region object containing multiple child objects.
- Returns:
- Returns GeoJSON string. Null will return if the type is not supported.
-
fromGeoJSON
public boolean fromGeoJSON(java.lang.String geoJSON)
Acquire Geometry from GeoJSON format string. The specific implementation is finished by subclass.- Parameters:
geoJSON
- The GeoJSON string.- Returns:
- Whether the conversion was successful.
-
fromXML
public boolean fromXML(java.lang.String xml)
Loading geometry objects from XML.- Parameters:
xml
- The XML string of the geometric object- Returns:
- boolean Return true if open successful; otherwise false.
-
toXML
public java.lang.String toXML()
Returns the XML string of the geometric object- Returns:
- Returns the XML string of the geometric object
-
-