CartoType C++ API 7.8.2, 2022-03-25
for Windows, Linux, Qt and other platforms supporting C++ development
|
#include <cartotype_map_object.h>
Classes | |
class | CMatch |
union | TUserData |
Public Types | |
enum class | TMatchType { None , Substring , Fuzzy , Phrase , Full } |
Public Member Functions | |
virtual std::unique_ptr< CMapObject > | Copy (TResult &aError) const |
virtual TText | StringAttributes () const =0 |
virtual TText | Label () const =0 |
virtual TWritableContour | WritableContour (size_t aIndex)=0 |
virtual MString * | WritableStringAttributes () |
virtual const TBitmap * | Bitmap () const |
virtual const TTransform * | BitmapTransform () const |
virtual void | Normalize () |
virtual void | Simplify (int32_t aResolution) |
void | Split (size_t aMaxPoints, CMapObjectArray &aExtraObjectArray) |
virtual TAttribSet * | AttribSet () |
const TAttribSet * | AttribSet () const |
virtual std::shared_ptr< CProjection > | Projection () const |
TText | GetStringAttribute (const MString &aName) const |
TText | GetStringAttribute (const CString &aName) const |
TText | GetStringAttributeForLocale (const MString &aName, const char *aLocale) const |
TText | GetStringAttributeForLocale (const CString &aName, const char *aLocale) const |
bool | GetStringAttributeUsingPath (const MString &aPath, const MString &aDefault, TText &aValue) const |
std::map< CString, CString > | GetStringAttributes () const |
uint64_t | Id () const |
TMapObjectType | Type () const |
uint32_t | IntAttribute () const |
const MString & | LayerName () const |
CRefCountedString | LayerRef () const |
CString | GenericName (const char *aLocale=nullptr) const |
std::string | Description () const |
std::string | VerboseDescription () const |
TPointFP | Center () const |
TPointFP | CenterInDegrees (TResult &aError) const |
TRectFP | BoundsInDegrees (TResult &aError) const |
CGeometry | GeometryInDegrees (TResult &aError) const |
bool | GetHeight (TPoint aPoint, bool aHaveMetres, const TTransform *aInverseTransform, int32_t &aHeight) const |
TGeoCodeType | GetGeoCodeType () const |
void | GetGeoCodeItem (CGeoCodeItem &aGeoCodeItem, const char *aLocale) const |
double | MaxSpeed () const |
double | Top () const |
double | Bottom () const |
double | DimensionAttribute (const MString &aKey) const |
bool | NextStringAttribute (size_t &aPos, TText &aName, TText &aValue) const |
bool | Mergeable (const CMapObject &aOther) const |
void | Project (const TMapTransform &aProjection) |
void | Project (const CProjection &aProjection) |
void | Smooth () |
void | Offset (int32_t aDx, int32_t aDy) |
bool | Clip (const TRect &aClip, std::unique_ptr< CMapObject > &aClippedObject, CMapObjectArray *aExtraClippedObjectArray=nullptr, bool aLinesMustBeSingleContours=false) const |
bool | Clip (const TClipRegion &aClip, std::unique_ptr< CMapObject > &aClippedObject, CMapObjectArray *aExtraClippedObjectArray=nullptr, bool aLinesMustBeSingleContours=false) const |
std::unique_ptr< CMapObject > | Flatten (double aDistance) const |
std::unique_ptr< CMapObject > | Interpolate (int32_t aGranularity) const |
void | SetType (TMapObjectType aType) |
TResult | Write (TDataOutputStream &aOutput, const CProjection *aProjectionFromLatLong=nullptr) const |
double | Area (TResult &aError) const |
double | LengthOrPerimeter (TResult &aError) const |
void | SetId (uint64_t aId) |
void | SetIntAttribute (uint32_t aValue) |
void | SetLayer (CRefCountedString aLayer) |
TResult | GetMatch (CMatch &aMatch, const MString &aText, TStringMatchMethod aMatchMethod, const MString *aAttributes=nullptr, bool aPhrase=true) const |
TMatchType | MatchType (const MString &aText) const |
void | SetUserData (int64_t aData) |
int64_t | UserData () const |
void | SetUserDataToPointer (void *aData) |
void * | UserDataAsPointer () const |
void | SetUserDataToUnion (TUserData aUserData) |
TUserData | UserDataAsUnion () const |
COutline | Clip (TClipOperation aClipOperation, const MPath &aClip) const |
Public Member Functions inherited from CartoType::MPath | |
virtual | ~MPath () |
virtual size_t | Contours () const =0 |
virtual TContour | Contour (size_t aIndex) const =0 |
virtual bool | MayHaveCurves () const =0 |
template<class MPathTraverser > | |
void | Traverse (MPathTraverser &aTraverser, const TRect &aClip) const |
template<class MPathTraverser > | |
void | Traverse (MPathTraverser &aTraverser, const TRect *aClip=nullptr) const |
bool | operator== (const MPath &aOther) const |
TRect | CBox () const |
bool | CBoxBiggerThan (int32_t aSize) const |
bool | IsContainedIn (const TRect &aRect) const |
bool | Contains (double aX, double aY) const |
bool | Contains (const TPoint &aPoint) const |
bool | Contains (const TPointFP &aPoint) const |
bool | MayIntersect (const TRect &aRect) const |
bool | MayIntersect (const TRect &aRect, int32_t aBorder) const |
bool | Intersects (const TRect &aRect) const |
bool | Intersects (const MPath &aPath, const TRect *aBounds=nullptr) const |
int32_t | MaxDistanceFromOrigin () const |
TPathIntersectionType | IntersectionType (const MPath &aOther, double *aDistance=nullptr, TPointFP *aNearest1=nullptr, TPointFP *aNearest2=nullptr) const |
TPathIntersectionInfo | IntersectionInfo (const MPath &aOther) const |
double | DistanceFrom (const MPath &aOther, TPointFP *aNearest1=nullptr, TPointFP *aNearest2=nullptr, TPathIntersectionType *aType=nullptr) const |
double | DistanceFromPoint (const TPointFP &aPoint, TPointFP *aNearest=nullptr, size_t *aContourIndex=nullptr, size_t *aLineIndex=nullptr, double *aFractionaLineIndex=nullptr, bool aTreatAsOpen=false) const |
bool | IsClippingNeeded (const TRect &aClip) const |
COutline | Copy () const |
COutline | ClippedPath (const TRect &aClip) const |
COutline | ClippedPath (const MPath &aClip) const |
COutline | ClippedPath (const TClipRegion &aClip) const |
COutline | Clip (TClipOperation aClipOperation, const MPath &aClip) const |
COutline | Envelope (double aOffset) const |
bool | IsSmoothingNeeded () const |
COutline | SmoothPath () const |
COutline | FlatPath (double aMaxDistance) const |
COutline | TruncatedPath (double aStart, double aEnd) const |
COutline | OffsetPath (double aOffset) const |
COutline | TransformedPath (const TTransform &aTransform) const |
COutline | TransformedPath (TDrawResult &aError, MPointTransformer &aTransformer, int32_t aFractionalBits) const |
std::array< TLine, 3 > | GetHorizontalPaths (int32_t aPathLength, int32_t aLabelHeight, const TPointFP &aUpVector, const TRect *aBounds, const TRect *aClip) const |
TPointFP | CenterOfGravity () const |
void | GetCenterOfGravity (TPoint &aCenter) const |
double | Length () const |
double | Area () const |
TPointFP | PointAtLength (double aPos) const |
std::pair< TPoint, bool > | End () const |
void | Write (TDataOutputStream &aOutput) const |
bool | IsEmpty () const |
bool | IsPoint () const |
bool | IsGridOrientedRectangle (TRect *aRect=nullptr) const |
void | GetSphericalAreaAndLength (const CProjection &aProjection, double *aArea, double *aLength) const |
TClipType | ClipType (const TRect &aRect) const |
bool | HasCurves () const |
ConstIter | begin () const |
ConstIter | end () const |
Protected Member Functions | |
CMapObject (CRefCountedString aLayer, TMapObjectType aType) | |
CMapObject (CRefCountedString aLayer, TMapObjectType aType, TUserData aUserData) | |
CMapObject (const CMapObject &aOther)=default | |
CMapObject & | operator= (const CMapObject &aOther)=default |
Protected Attributes | |
CRefCountedString | iLayer |
uint64_t | iId = 0 |
TMapObjectType | iType |
uint32_t | iIntAttribute = 0 |
TUserData | iUserData |
The abstract base map object class. A map object is a path that also possesses cartographic attributes.
|
strong |
A type for different qualities of text match.
|
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 CartoType::CMapObject::Area | ( | TResult & | 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 CartoType::CMapObject::Bottom | ( | ) | const |
Gets the bottom of an object in metres by reading it from the _b attribute. Return 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.
TPointFP CartoType::CMapObject::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.
bool CartoType::CMapObject::Clip | ( | const TClipRegion & | aClip, |
std::unique_ptr< CMapObject > & | aClippedObject, | ||
CMapObjectArray * | 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 CartoType::CMapObject::Clip | ( | const TRect & | aClip, |
std::unique_ptr< CMapObject > & | aClippedObject, | ||
CMapObjectArray * | 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.
COutline CartoType::MPath::Clip | ( | TClipOperation | 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.
|
virtual |
Creates a copy of a map object. The base implementation works for all types of map object except array map objects.
std::string CartoType::CMapObject::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, OSM type and object type in square brackets. The object type is encoded as a single character: . - @ # for point, line, polygon and array.
double CartoType::CMapObject::DimensionAttribute | ( | const MString & | aKey | ) | const |
Gets the value of a OpenStreetMap dimension attribute in meters.
std::unique_ptr< CMapObject > CartoType::CMapObject::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.
CString CartoType::CMapObject::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.
Returns the geometry of a map object in degrees.
void CartoType::CMapObject::GetGeoCodeItem | ( | CGeoCodeItem & | aGeoCodeItem, |
const char * | aLocale | ||
) | const |
Gets information used when geocoding a map object.
TGeoCodeType CartoType::CMapObject::GetGeoCodeType | ( | ) | const |
Returns the geocode type of a map object.
bool CartoType::CMapObject::GetHeight | ( | TPoint | aPoint, |
bool | aHaveMetres, | ||
const TTransform * | 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.
TResult CartoType::CMapObject::GetMatch | ( | CMatch & | aMatch, |
const MString & | aText, | ||
TStringMatchMethod | aMatchMethod, | ||
const MString * | aAttributes = nullptr , |
||
bool | aPhrase = true |
||
) | const |
Finds the first string attribute matching aText, using aMatchMethod, and returns information about it in aMatch. 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.
Gets the value of the string attribute with name aName.
Gets the value of the string attribute with name aName.
|
inline |
Gets a string attribute for a given locale by appending a colon then the locale to aName. If no such attribute is available use the locale truncated to two letters if it was longer, then try the plain name. The empty attribute name is changed to 'name' if a locale is added.
TText CartoType::CMapObject::GetStringAttributeForLocale | ( | const MString & | aName, |
const char * | aLocale | ||
) | const |
Gets a string attribute for a given locale by appending a colon then the locale to aName. If no such attribute is available use the locale truncated to two letters if it was longer, then try the plain name. The empty attribute name is changed to 'name' if a locale is added.
Gets all the string attributes as a std::map from names to values.
bool CartoType::CMapObject::GetStringAttributeUsingPath | ( | const MString & | aPath, |
const MString & | aDefault, | ||
TText & | aValue | ||
) | const |
Gets 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.
Returns true if the returned attribute is a name attribute, defined as the empty attribute, or 'name', or any attribute starting with 'name:'.
|
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'.
|
inline |
Returns the integer attribute.
std::unique_ptr< CMapObject > CartoType::CMapObject::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 CartoType::CMapObject::LengthOrPerimeter | ( | TResult & | 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.
TMatchType CartoType::CMapObject::MatchType | ( | const MString & | aText | ) | const |
Finds out whether a map object is a partial or full match for some text.
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.
double CartoType::CMapObject::MaxSpeed | ( | ) | const |
If the string attribute '_s' exists, treats it as a maximum speed represented according to OpenStreetMap conventions and returns the value in kilometres per hour.
The speed limit is stored as either a plain number denoting kph, a number followed by 'mph' denoting miles per hour, or a country code followed by a category as defined in http://wiki.openstreetmap.org/wiki/Speed_limits.
bool CartoType::CMapObject::Mergeable | ( | const CMapObject & | aOther | ) | const |
Returns true if this map object can be merged with aOther.
bool CartoType::CMapObject::NextStringAttribute | ( | size_t & | aPos, |
TText & | aName, | ||
TText & | 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 CartoType::CMapObject::Offset | ( | int32_t | aDx, |
int32_t | aDy | ||
) |
Offsets all points in the map object by the specified amounts.
|
protecteddefault |
The assignment operator.
void CartoType::CMapObject::Project | ( | const CProjection & | aProjection | ) |
Projects all the points in a map object using the specified projection.
void CartoType::CMapObject::Project | ( | const TMapTransform & | aProjection | ) |
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 ID.
|
inline |
Sets the 32-bit integer attribute, which contains the road type if the object is a road.
|
inline |
Sets the layer.
|
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 CartoType::CMapObject::Smooth | ( | ) |
Smooths a map object by converting sequences of straight lines to curves.
void CartoType::CMapObject::Split | ( | size_t | aMaxPoints, |
CMapObjectArray & | aExtraObjectArray | ||
) |
Splits a line object into objects with no more than aMaxPoints points each. Puts any extra objects created into aExtraObjectArray.
|
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.
double CartoType::CMapObject::Top | ( | ) | const |
Gets the top of an object in metres by reading it from the _t attribute. Return 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 CartoType::CMapObject::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.
TResult CartoType::CMapObject::Write | ( | TDataOutputStream & | aOutput, |
const CProjection * | 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.)
|
protected |
The object's identifier.
|
protected |
The integer attribute, used for road types, routing flags, or sub-types of layers.
|
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.