CartoType C++ API 8.8-7-gb35e4dc71
for Windows, Linux, Qt and other platforms supporting C++ development
|
#include <cartotype_map_object.h>
Public Member Functions | |
virtual std::unique_ptr< MapObject > | Copy (Result &aError) const |
virtual Text | StringAttributes () const =0 |
virtual Text | Label () const =0 |
virtual WritableContourView | WritableContour (size_t aIndex)=0 |
virtual MString * | WritableStringAttributes () |
virtual const BitmapView * | Bitmap () const |
virtual const AffineTransform * | BitmapTransform () const |
virtual void | Normalize () |
virtual void | Simplify (int32_t aResolution) |
virtual TAttribSet * | AttribSet () |
const TAttribSet * | AttribSet () const |
virtual std::shared_ptr< CartoTypeCore::Projection > | Projection () const |
Text | StringAttribute (const MString &aName) const |
Text | StringAttribute (const String &aName) const |
Text | StringAttributeForLocale (const MString &aName, const char *aLocale) const |
Text | StringAttributeForLocale (const String &aName, const char *aLocale) const |
Text | StringAttributeUsingPath (const MString &aPath, const MString &aDefault, Font *aFont=nullptr) const |
std::map< String, String > | StringAttributeMap () const |
uint64_t | Id () const |
MapObjectType | Type () const |
const MString & | LayerName () const |
RefCountedString | LayerRef () const |
CartoTypeCore::FeatureInfo | FeatureInfo () const |
String | GenericName (const char *aLocale=nullptr) const |
std::string | Description () const |
std::string | VerboseDescription () const |
PointFP | Center () const |
PointFP | CenterInDegrees (Result &aError) const |
RectFP | BoundsInDegrees (Result &aError) const |
Geometry | GeometryInDegrees (Result &aError) const |
bool | GetHeight (Point aPoint, bool aHaveMetres, const AffineTransform *aInverseTransform, int32_t &aHeight) const |
CartoTypeCore::GeoCodeType | GeoCodeType () const |
CartoTypeCore::GeoCodeItem | GeoCodeItem (const char *aLocale) const |
double | SpeedLimit () const |
double | Top () const |
double | Bottom () const |
double | DimensionAttribute (const MString &aKey) const |
bool | NextStringAttribute (size_t &aPos, Text &aName, Text &aValue) const |
bool | Mergeable (const MapObject &aOther) const |
void | Project (const MapTransform &aMapTransform) |
void | Project (const CartoTypeCore::Projection &aProjection) |
void | Smooth () |
void | Offset (int32_t aDx, int32_t aDy) |
bool | Clip (const Rect &aClip, std::unique_ptr< MapObject > &aClippedObject, MapObjectArray *aExtraClippedObjectArray=nullptr, bool aLinesMustBeSingleContours=false) const |
bool | Clip (const ClipRegion &aClip, std::unique_ptr< MapObject > &aClippedObject, MapObjectArray *aExtraClippedObjectArray=nullptr, bool aLinesMustBeSingleContours=false) const |
std::unique_ptr< MapObject > | Flatten (double aDistance) const |
std::unique_ptr< MapObject > | Interpolate (int32_t aGranularity) const |
void | SetType (MapObjectType aType) |
Result | Write (OutputStream &aOutput, const CartoTypeCore::Projection *aProjectionFromLatLong=nullptr) const |
void | WriteInMapCoords (OutputStream &aOutput) const |
double | Area (Result &aError) const |
double | LengthOrPerimeter (Result &aError) const |
void | SetId (uint64_t aId) |
void | SetFeatureInfo (CartoTypeCore::FeatureInfo aFeatureInfo) |
CartoTypeCore::FeatureType | FeatureType () const |
Result | SetSubType (uint32_t aSubType) |
uint32_t | SubType () const |
void | SetLayer (RefCountedString aLayer) |
MapObjectMatch | Match (const MString &aText, StringMatchMethod aMatchMethod, const MString *aAttributes=nullptr, bool aPhrase=true) const |
StringMatchType | MatchType (const MString &aText, const AbbreviationDictionary *aAbbreviationDictionary=nullptr) const |
void | SetUserData (int64_t aData) |
int64_t | UserData () const |
void | SetUserDataToPointer (void *aData) |
void * | UserDataAsPointer () const |
void | SetUserDataToUnion (CartoTypeCore::UserData aUserData) |
CartoTypeCore::UserData | UserDataAsUnion () const |
Outline | Clip (ClipOperation aClipOperation, const MPath &aClip) const |
Public Member Functions inherited from CartoTypeCore::MPath | |
virtual | ~MPath () |
virtual size_t | Contours () const =0 |
virtual ContourView | ContourByIndex (size_t aIndex) const =0 |
virtual bool | MayHaveCurves () const =0 |
template<class MPathTraverser > | |
void | Traverse (MPathTraverser &aTraverser, const Rect &aClip) const |
template<class MPathTraverser > | |
void | Traverse (MPathTraverser &aTraverser, const Rect *aClip=nullptr) const |
bool | operator== (const MPath &aOther) const |
Rect | CBox () const |
bool | CBoxBiggerThan (int32_t aSize) const |
bool | IsContainedIn (const Rect &aRect) const |
bool | Contains (double aX, double aY) const |
bool | Contains (const Point &aPoint) const |
bool | Contains (const PointFP &aPoint) const |
bool | MayIntersect (const Rect &aRect) const |
bool | MayIntersect (const Rect &aRect, int32_t aBorder) const |
bool | Intersects (const Rect &aRect) const |
bool | Intersects (const MPath &aPath, const Rect *aBounds=nullptr) const |
int32_t | MaxDistanceFromOrigin () const |
PathIntersectionType | IntersectionType (const MPath &aOther, double *aDistance=nullptr, PointFP *aNearest1=nullptr, PointFP *aNearest2=nullptr) const |
PathIntersectionInfo | IntersectionInfo (const MPath &aOther) const |
double | DistanceFrom (const MPath &aOther, PointFP *aNearest1=nullptr, PointFP *aNearest2=nullptr, PathIntersectionType *aType=nullptr) const |
double | DistanceFromPoint (const PointFP &aPoint, PointFP *aNearest=nullptr, size_t *aContourIndex=nullptr, size_t *aLineIndex=nullptr, double *aFractionaLineIndex=nullptr, bool aTreatAsOpen=false) const |
bool | IsClippingNeeded (const Rect &aClip) const |
Outline | Copy () const |
Outline | ClippedPath (const Rect &aClip) const |
Outline | ClippedPath (const MPath &aClip) const |
Outline | ClippedPath (const ClipRegion &aClip) const |
Outline | Clip (ClipOperation aClipOperation, const MPath &aClip) const |
Outline | Envelope (double aOffset) const |
Outline | ConcaveHull (double aMaxEdgeLength, PolygonOrientation aAssumedOrientation=PolygonOrientation::None) const |
bool | IsSmoothingNeeded () const |
Outline | SmoothPath () const |
Outline | FlatPath (double aMaxDistance) const |
Outline | TruncatedPath (double aStart, double aEnd) const |
Outline | OffsetPath (double aOffset) const |
Outline | TransformedPath (const AffineTransform &aTransform) const |
Outline | TransformedPath (DrawResult &aError, MPointTransformer &aTransformer, int32_t aFractionalBits) const |
Outline | Interpolate (int32_t aGranularity) const |
std::array< Line, 3 > | HorizontalPaths (GraphicsContext *aGc, int32_t aPathLength, int32_t aLabelAscent, int32_t aLabelDescent, const PointFP &aUpVector, const Rect *aBounds, const Rect *aClip) const |
PointFP | CenterOfGravity () const |
double | Length () const |
double | Area () const |
PointFP | PointAtLength (double aPos) const |
std::pair< Point, bool > | End () const |
void | Write (OutputStream &aOutput) const |
void | WriteAsXml (OutputStream &aOutput) const |
bool | IsEmpty () const |
bool | IsPoint () const |
bool | IsGridOrientedRectangle (Rect *aRect=nullptr) const |
void | GetSphericalAreaAndLength (const Projection &aProjection, double *aArea, double *aLength) const |
CartoTypeCore::ClipType | ClipType (const Rect &aRect) const |
bool | HasCurves () const |
size_t | PointCount () const |
ConstIter | begin () const |
ConstIter | end () const |
Static Public Member Functions | |
static double | SpeedLimit (const MString &aStringAttribute) |
Protected Member Functions | |
MapObject (RefCountedString aLayer, MapObjectType aType) | |
MapObject (RefCountedString aLayer, MapObjectType aType, CartoTypeCore::UserData aUserData) | |
MapObject (const MapObject &aOther)=default | |
MapObject & | operator= (const MapObject &aOther)=default |
Protected Attributes | |
RefCountedString | iLayer |
uint64_t | iId = 0 |
MapObjectType | iType |
CartoTypeCore::FeatureInfo | iFeatureInfo |
CartoTypeCore::UserData | iUserData |
The abstract base map object class. A map object is a path that also possesses cartographic attributes.
|
inlineprotected |
Creates a map object with a specified layer and type.
|
inlineprotected |
Creates a map object with a specified layer, type and user data.
|
protecteddefault |
Creates a map object by copying another one.
double CartoTypeCore::MapObject::Area | ( | Result & | aError | ) | const |
Calculates the area of a map object in square meters, using the projection stored in the map object. Returns 0 if the object is a point or line object.
|
inlinevirtual |
Returns a pointer to a TAttribSet if possible; used by makemap.
|
inline |
Returns a constant pointer to a TAttribSet if possible; used by makemap.
|
virtual |
If the object contains array data that can be represented as a bitmap, returns a pointer to the bitmap. The base implementation returns null.
|
virtual |
If the object contains array data that can be represented as a bitmap, returns a transform to convert from the bitmap bounds to the extent in map coordinates. The base implementation returns null.
double CartoTypeCore::MapObject::Bottom | ( | ) | const |
Gets the bottom of an object in metres by reading it from the _b attribute. Returns 0 if no bottom is specified. The _b attribute is a copy of the OpenStreetMap 'min_height' attribute.
Returns the bounding box of a map object in degrees.
PointFP CartoTypeCore::MapObject::Center | ( | ) | const |
Returns the center of a map object in map coordinates. The center is defined as the center of gravity for polygons and arrays, a point half way along the path for lines, and the point itself for points.
Returns the center of a map object in degrees. The center is defined as the center of gravity for polygons and arrays, a point half way along the path for lines, and the point itself for points. Because the center is calculated using map coordinates then converted to degrees, it depends on the map projection used by the map object.
Outline CartoTypeCore::MPath::Clip | ( | ClipOperation | aClipOperation, |
const MPath & | aClip | ||
) | const |
Performs a general clip operation, which is one of clip, union, difference and exclusive or, on this path using aClip as the clip path, and returns the resulting path. The clipping path (aClip) must be made from closed contours only.
bool CartoTypeCore::MapObject::Clip | ( | const ClipRegion & | aClip, |
std::unique_ptr< MapObject > & | aClippedObject, | ||
MapObjectArray * | aExtraClippedObjectArray = nullptr , |
||
bool | aLinesMustBeSingleContours = false |
||
) | const |
Clips a map object to the clip region aClip.
If the object was clipped the function returns true and puts the clipped object, which may be null, in aClippedObject.
If aExtraClippedObjectArray is non-null, line objects with a single contour may be clipped into multiple objects to preserve their single-line nature, in which case the extra objects are appended to aExtraClippedObjectArray. All other objects are clipped to a single object.
If aLinesMustBeSingleContours is true, line objects are never converted to multiple contours, even if aExtraClippedObjectArray is non-null. They are not clipped if that is necessary.
If the object was not clipped (i.e., it was entirely contained in aClip) the function returns false.
bool CartoTypeCore::MapObject::Clip | ( | const Rect & | aClip, |
std::unique_ptr< MapObject > & | aClippedObject, | ||
MapObjectArray * | aExtraClippedObjectArray = nullptr , |
||
bool | aLinesMustBeSingleContours = false |
||
) | const |
Clips a map object to the rectangle aClip.
If the object was clipped the function returns true and puts the clipped object, which may be null, in aClippedObject.
If aExtraClippedObjectArray is non-null, line objects with a single contour may be clipped into multiple objects to preserve their single-line nature, in which case the extra objects are appended to aExtraClippedObjectArray. All other objects are clipped to a single object.
If aLinesMustBeSingleContours is true, line objects are never converted to multiple contours, even if aExtraClippedObjectArray is non-null. They are not clipped if that is necessary.
If the object was not clipped (i.e., it was entirely contained in aClip) the function returns false.
|
virtual |
Creates a copy of a map object. The base implementation works for all types of map object except array map objects.
std::string CartoTypeCore::MapObject::Description | ( | ) | const |
Creates a UTF-8 string describing a map object; used for debugging. The string consists of the object's string attributes, separated by | characters, then the layer, feature type and object type in square brackets. The object type is encoded as a single character: . - @ # for point, line, polygon and array.
double CartoTypeCore::MapObject::DimensionAttribute | ( | const MString & | aKey | ) | const |
Returns the value of a OpenStreetMap dimension attribute in meters.
|
inline |
Returns the feature info.
|
inline |
Returns the feature type.
std::unique_ptr< MapObject > CartoTypeCore::MapObject::Flatten | ( | double | aDistance | ) | const |
Returns a version of a map object with all curved line segments flattened by being replaced by short straight line segments. Returns null if no flattening is needed.
String CartoTypeCore::MapObject::GenericName | ( | const char * | aLocale = nullptr | ) | const |
Creates a generic name for a map object, using the supplied locale if possible. For example "restaurant", "fuel station" or "minor road".
Note: locales are not yet implemented. All category names are in English.
CartoTypeCore::GeoCodeItem CartoTypeCore::MapObject::GeoCodeItem | ( | const char * | aLocale | ) | const |
Returns information used when geocoding a map object.
CartoTypeCore::GeoCodeType CartoTypeCore::MapObject::GeoCodeType | ( | ) | const |
Returns the geocode type of a map object.
Returns the geometry of a map object in degrees.
bool CartoTypeCore::MapObject::GetHeight | ( | Point | aPoint, |
bool | aHaveMetres, | ||
const AffineTransform * | aInverseTransform, | ||
int32_t & | aHeight | ||
) | const |
Gets the height of a point in metres if this map object contains terrain heights. The argument aPoint is in map coordinates. The return value is true if a height is successfully obtained.
There is no check for the validity or sanity of the data. The argument aHaveMetres indicates whether the object contains 16-bit metre values, or bytes encoding feet.
Feet are encoded as follows: 0 for unknown heights (sea or unspecified); 1...15 for -1400ft to sea level in intervals of 100ft; 16...195 for 100ft to 18,000ft in intervals of 100ft; and 196...255 for 18,200ft to 30,000ft in intervals of 200ft.
If aInverseTransform is supplied, it is the inverse of the transform used to convert from bitmap coordinates to map coordinates. If it is not supplied, it is calculated from the bitmap.
|
inline |
Returns the identifier of this object. Identifiers are opaque 64-bit numbers that are specific to a database. The value zero is reserved and means 'no identifier'.
std::unique_ptr< MapObject > CartoTypeCore::MapObject::Interpolate | ( | int32_t | aGranularity | ) | const |
Creates a new map object, interpolating extra points so that the maximum difference between coordinates doesn't exceed aGranularity. Chooses the points to be interpolated using the coordinate modulo aGranularity, so that adjacent polygons have the same interpolated points and thus meet without gaps.
|
pure virtual |
Returns the default label or name of the object: the first, unnamed, string attribute.
|
inline |
Returns the name of the layer this object belongs to.
|
inline |
Returns the reference-counted name of the layer.
double CartoTypeCore::MapObject::LengthOrPerimeter | ( | Result & | aError | ) | const |
Calculates the length or perimeter of a map object in meters, using the projection stored in the map object. Returns 0 if the object is a point object.
MapObjectMatch CartoTypeCore::MapObject::Match | ( | const MString & | aText, |
StringMatchMethod | aMatchMethod, | ||
const MString * | aAttributes = nullptr , |
||
bool | aPhrase = true |
||
) | const |
Finds the first string attribute matching aText, using aMatchMethod, and returns information about it. If aAttributes is non-null, examines only attributes in the supplied comma-separated list, otherwise examines all attributes except those starting with an underscore, which by convention are non-textual. Attribute names may contain the wild cards ? and *. If aPhrase is true (the default), allows matches of phrases within the attribute.
StringMatchType CartoTypeCore::MapObject::MatchType | ( | const MString & | aText, |
const AbbreviationDictionary * | aAbbreviationDictionary = nullptr |
||
) | const |
Finds out whether a map object is a partial or full match for some text. If aAbbreviationDictionary is non-null, attributes are abbreviated using it before being compared with aText.
If the text matches the whole of a name attribute, or the whole of a sub-part of a name attribute (using spaces, hyphens, single quotes, colons, semicolons and slashes as separators) ignoring case and accents, it's a phrase match or a fuzzy match.
If it matches part of the attribute it's a phrase match.
bool CartoTypeCore::MapObject::Mergeable | ( | const MapObject & | aOther | ) | const |
Returns true if this map object can be merged with aOther.
bool CartoTypeCore::MapObject::NextStringAttribute | ( | size_t & | aPos, |
Text & | aName, | ||
Text & | aValue | ||
) | const |
Gets the next string attribute, starting at character position aPos in the string attributes, and updates aPos. Returns true if an attribute is found.
This function can be used to enumerate string attributes by passing 0 as aPos and repeating until a value of false is returned.
|
virtual |
Normalizes a map object if possible by removing point contours with no points, polygon contours with fewer than 3 points, and line contours with fewer than 2 points. The base implementation does nothing.
void CartoTypeCore::MapObject::Offset | ( | int32_t | aDx, |
int32_t | aDy | ||
) |
Offsets all points in the map object by the specified amounts.
The assignment operator.
void CartoTypeCore::MapObject::Project | ( | const CartoTypeCore::Projection & | aProjection | ) |
Projects all the points in a map object using the specified projection.
void CartoTypeCore::MapObject::Project | ( | const MapTransform & | aMapTransform | ) |
Projects all the points in a map object to 64ths of pixels using the specified projection.
|
inlinevirtual |
Returns the projection used to convert from degrees of latitude and longitude to the map units used by this object, or null if the projection is not known.
|
inline |
Sets the feature information, which contains the road type if the object is a road.
|
inline |
Sets the ID.
|
inline |
Sets the layer.
Result CartoTypeCore::MapObject::SetSubType | ( | uint32_t | aSubType | ) |
Sets the integer sub-type of a non-route object. Returns an error if the sub-type is outside the legal range 0...2047, or if this object is a route object.
|
inline |
Sets the map object type.
|
inline |
Sets the user data to a 64-bit integer.
|
inline |
Sets the user data to a pointer.
|
inline |
Sets the user data to a union
|
virtual |
Simplifies a map object, if possible, by re-sampling it at a specified resolution. The base implementation does nothing.
void CartoTypeCore::MapObject::Smooth | ( | ) |
Smooths a map object by converting sequences of straight lines to curves.
double CartoTypeCore::MapObject::SpeedLimit | ( | ) | const |
Returns the speed limit in kph for this object if it is a route object. Returns 0 if it is not a route object or if the speed limit is unknown or if there is no speed limit.
|
static |
Gets the speed limit in kph from the string attribute _s, if it exists in aStringAttribute.
Returns the value of the string attribute with name aName.
Returns the value of the string attribute with name aName.
Text CartoTypeCore::MapObject::StringAttributeForLocale | ( | const MString & | aName, |
const char * | aLocale | ||
) | const |
Returns a string attribute for a given locale by appending a colon then the locale to aName. If no such attribute is available, uses the locale truncated to two letters if it was longer, then tries the plain name. The empty attribute name is changed to 'name' if a locale is added.
|
inline |
Returns a string attribute for a given locale by appending a colon then the locale to aName. If no such attribute is available, uses the locale truncated to two letters if it was longer, then tries the plain name. The empty attribute name is changed to 'name' if a locale is added.
Returns all the string attributes as a std::map from names to values.
|
pure virtual |
Returns all the string attributes, null-separated, as key-value pairs separated by an equals sign. The first key must be empty, and means the label or name.
Text CartoTypeCore::MapObject::StringAttributeUsingPath | ( | const MString & | aPath, |
const MString & | aDefault, | ||
Font * | aFont = nullptr |
||
) | const |
Returns a string attribute from a list of semi-colon-separated names in aPath. Replaces empty names with aDefault (as for example if aPath is empty and aDefault is 'name:es'). Returns the first non-empty result.
If aFont is non-null, string attributes that are not drawable (have missing glyphs) using aFont are not returned.
|
inline |
Returns the integer sub-type if this is a non-route object. Returns 0 for route objects.
double CartoTypeCore::MapObject::Top | ( | ) | const |
Gets the top of an object in metres by reading it from the _t attribute. Returns 0 if no top is specified. The _t attribute is a copy of the OpenStreetMap 'height' attribute.
|
inline |
Returns the type of the object.
|
inline |
Returns the user data as a 64-bit integer.
|
inline |
Returns the user data as a pointer.
|
inline |
Returns the user data as a union.
std::string CartoTypeCore::MapObject::VerboseDescription | ( | ) | const |
Creates a verbose English-language description of a map object as a UTF-8 string.
|
pure virtual |
Returns a writable interface to the contour indexed by aIndex.
|
inlinevirtual |
Returns a pointer to writable string attributes if possible; used by makemap.
Result CartoTypeCore::MapObject::Write | ( | OutputStream & | aOutput, |
const CartoTypeCore::Projection * | aProjectionFromLatLong = nullptr |
||
) | const |
Writes a map object to an output stream in serialized form. Writes the geometry as degrees lat/long. (For internal use only : if the map object doesn't store its projection, which is true of stack-allocated CTM1 objects, the projection must be supplied.)
void CartoTypeCore::MapObject::WriteInMapCoords | ( | OutputStream & | aOutput | ) | const |
(For internal use only) Writes a map object to an output stream in serialized form. Writes the geometry in map coordinates. Writes the user data.
|
protected |
The feature type, level, road direction, etc., packed into a 32-bit value.
|
protected |
The object's identifier.
|
protected |
The layer this object belongs to.
|
protected |
The type of the object: point, line, polygon, etc.
|
protected |
User data; can hold an integer or a pointer; can be used to associate any value with a map object.