Composant Delphi / Google Maps / OpenStreetMap / Leaflet  / Mappilary / Native Maps 100% Delphi 0% WebBrowser 0% Javascript

Import/Export

you are here :TECNativeMap

TECNativeMap allows to save and reload all of its data in a simple text file, this includes not only the component settings and views but also the map data

Alternatively, you can import/export your data in formats GPX , GeoJSON and KML

Backup/restore

function SaveToFile(const filename:string):boolean;

Saves the map to a text file.

Use extensions .gpx, .json, .kml to specify a format, otherwise it is the internal format of ECNativeMap that will be used

function LoadFromFile(const filename:string):boolean;

Charge la carte avec un fichier texte

Use extensions .gpx .kml to specify a format, otherwise it is the internal format of ECNativeMap that will be used

 

LoadFromFile can download files on internet

69

 

property toGPX : string;

Property read/write which gives access to the data of the card in GPX format.

property toTxt : string;

Property read/write which gives access to the data of the card in a text format.

property ToKml : string;

Property in reading / writing which returns the geographical elements of the map in Kml format

property toGeoJson : string;

Property read/write which gives access to the data of the card in the GeoJson format.

You access to the "properties" with TECShape.Properties field data, see chapter on the vector tiles to learn how to styling your items.

This property is used by SaveToFile, LoadFromFile.

Events

During loading the map the event OnLoadShapes(sender: TObject; const ShapeType:string; const index, max: integer; var cancel: boolean) fires
for each item added.

ShapeType can have the values 'TECShapePOI', 'TECShapeMarker', 'TECShapeLine' , 'TECShapePolygone' and 'TECShapeInfoWindow'.

Index indicates the number of the currently loaded element and Max the total number of items to be loaded.

You can cancel the load switching cancel to true

When the file was loaded event OnLoad(sender: TObject;const GroupName:string;const FinishLoading : boolean) is triggered

GroupName contains the name of the Group that has been loaded, empty for direct loading of the map (default group)

FinishLoading true if the file has been loaded in totality and false if it was abandoned by switching cancel to true


OSM XML

TOSMFile (uecOSM unit) allows you to work with files in the OSM XML format (base format of OpenMapStreet)

You can download parts of the world in this format on geofabrik.de, take .osm.bz2 and unzip them

OSM XML is large, some files are several Giga, TOSMFile can use an internal format (.olt) up to 19 times lighter, 10 times faster to process.

To convert a .osm file in .olt use the procedure OSMFileToOLT(const OSMFilename:string;const Notify:TNOtifyEvent=nil);

The conversion is performed in a thread and Notify is called when the work is complete.

rocedure TForm2.SaveOLTClick(Sender : TObject);
begin

// doEndSaveToOLT is call when file is saved
OSMFileToOLT(FOSMFile.filename, doEndSaveToOLT);

end;

procedure TForm2.doEndSaveToOLT(Sender : TObject);
begin
// here your osm file is savec in .olt

end;

Use TOSMFile to convert portions of OSM files

70

TOMSFile

function LoadFromFile(const sFilename : string) : boolean;
function LoadFromStream(const OSMStream : TStream) : boolean;
function LoadFromString(const OSMData : string) : boolean;

Loads a OSM or OLT file, the treatment takes place in a Thread so it does not block your program

property FilterPrimitive : TSetPrimitiveOSM ;

There are nodes, ways and relations.

// handle all primitive
FOSMFile.FilterPrimitive := [poNode,poWay,poRelation];

If you want to know simply the area geographical covered by the file without loading the data, filter all !

19
FOSMFile.FilterPrimitive := [];

property FilterBounds : TFilterBounds;

Determines the geographical areas that interest us, data outside are ignored.

FOSMFile.FilterBounds.Clear;
FOSMFile.FilterBounds.Add(Area1_NorthEastLat, Area1_NorthEastLng, Area1_SouthWestLat, Area1_SouthWestLng);
FOSMFile.FilterBounds.Add(Area2_NorthEastLat, Area2_NorthEastLng, Area2_SouthWestLat, Area2_SouthWestLng);

property FilterNode : TListFilterOSM;
property FilterWay : TListFilterOSM;
property FilterRelation : TListFilterOSM;

Filters items based on their keys and values, filters down from the class TFilterOSM

ExcludeKeyValue(const Key, Value : string), OnlyKeyValue(const Key, Value : string), ExcludeIfKeyExist(const Key:string) and OnlyIfKeyExist(const Key:string) simplifies the creation of filters.

71
FOSMFile.FilterWay.clear;
FOSMFile.FilterWay.ExcludeIfKeyExist('building');
FOSMFile.FilterWay.ExcludeKeyValue('leisure','park');
FOSMFile.FilterWay.ExcludeKeyValue('natural','coastline');
function ReLoad : boolean;
Reload a file after changing the filters, the keys and values are not recharged allows to earn a few seconds.

procedure saveToFile(const Filename : string; NotifyEvent : TNotifyEvent = nil);
You can save in the proprietary .olt format or in GeoJSON format
// save in geojson
FOSMFile.SaveToFile('path_myfile.geojson');
// save in olt
FOSMFile.SaveToFile('path_myfile.olt');

To save in a thread add a NotifyEvent

72
procedure TForm2.SaveOLTClick(Sender : TObject);
begin
// doEndSaveToOLT is call when file is saved
FOSMFile.SaveToFile('path_myfile.olt',doEndSaveToOLT);
end;

procedure TForm2.doEndSaveToOLT(Sender : TObject);
begin
// here your osm file is savec in .olt
end;
property Nodes : TNodeList read FNodeList;
property Ways : TWayList read FWayList;
property Relations : TRelationList read FRelationList;

Lists of the elements contained in the file after filtering.

Each list has functions for performing research on these items.

Find(idElement) Returns an item based on its id

The various Search functions fill the SearchResult list with the elements eligible

function Search(const Lat, Lng, radiusKM : double) : integer; overload;
Find all items located in an area centered around the point Lat, Lng and radius radiusKM

function Search(const SWLat, SWLng, NELat, NELng : double) : integer; overload;
Finds all elements in the area.

function Search(const SWLat, SWLng, NELat, NELng : double; const Key, Values : string) : integer; overload;
Finds all elements in the area with Key containing the specified values.

function Search(const Key, Values : string) : integer; overload;
Find all items whose key contains values.

// search all nodes with amenity=car or amenity=bar or amenity=restaurant
FOSMFile.Nodes.Search('amenity','cafe|bar|restaurant');

// search all ways with highway=residential or highway=secondary
FOSMFile.Ways.Search('highway','residential|secondary');

function Search(const Key : string) : integer; overload;
Find all items with this key, regardless of the value.



procedure Clear;

procedure Abort;
Abandons a loading

procedure ToShapes(Shapes:TECShapes;NotifyEvent:TNotifyEvent=nil);

Loads data into a group.

// load in default group
FOSMFile.ToShapes(map.Shapes);
procedure FindToShapes(Shapes:TECShapes;NotifyEvent:TNotifyEvent=nil);

Loads the search data in a group.

// search all nodes with amenity=car or amenity=bar or amenity=restaurant
FOSMFile.Nodes.Search('amenity','cafe|bar|restaurant');

// search all ways with highway=residential or highway=secondary
FOSMFile.Ways.Search('highway','residential|secondary');

// load in default group
FOSMFile.FindToShapes(map.Shapes);


function CountKey(Node: TBaseOSM):integer;
Returns the number of tag for an element

function getKey(Node:TBaseOSM;const index:integer):string;
Returns the key which is the index

function ReadKey(Node : TBaseOSM; const KeyName : string) : string; overload;
Returns the value of the Key

function ReadKey(Node : TBaseOSM) : string; overload;
Returns the set of key/value pairs in the form: Key1=value1#13#10Key2=value2#13#10Keyx=ValueX

function ReadValuesForKey(const KeyName : string; valuesList : TStringList): integer;
ValuesList filled with all of the values for a Key


property Aborted : boolean;
Indicates if loading has been interrupted by Abort

property Bounds : TBoundsLatLng ;
Contains the geographical area covered by the file


property FileFormat: TFileTypeOSM;
Returns the file type (ftOSM ou ftOLT)

property Filename : string ;
property FileSize : int64;

property Keys : TUniqueStringList;
List of all of the Key from the file

property Values : TUniqueStringList;
List of all the Value of the file

property Role[Member : TMemberOSM]:string;
Returns the role of a member of a relation

property Timestamp : string ;
Returns the date of the last update of the file



property OnRead : TOnOSMBlockRead;
To be able to process files of several Giga reading is made by block, this event is raised every time a block is read.

property OnLoaded : TNotifyEvent;
Raised when the entire file has been processed.

Check out DemoOSMViewer to see how to use TOSMFile

8

OSMViewer

Fig. 83 Demo OSMViewer

Convert OSM in OLT

Open the osm file in OSMviewer, the area covered is displayed on the map

Check the primitives that you want to export (nodes, ways and relations), and then click Save OLT to start the conversion


Fig. 84 Select nodes

Depending on the size of the OSM file work may take several minutes.

73

To export the ways all the nodes are kept in memory , you need 1 MB of memory per Giga of file.

If you convert only the nodes you can work with 100 Giga files even if you have only 8 MB of memory.

27
Click right and while holding the button move the mouse to define an area to explore.

Fig. 85 Selecting an area

Once the loaded zone you will have the choice between displayed data on the map or save them in .olt

By loading data you can search according to key/value pairs

Fig. 86 search highway=residential

Download OSMViewer

You can download an apk for android to a mini demo that displays a small area OSM data.

Fig. 87 Android Test OLT

Image capture

You can save the viewable area of the screen with the ScreenShot property that is an TBitmap

// Delphi map component TECNativeMap

// save map to bmp file
map.Screenshot('c:\mymap.bmp');

Alternatively, you can capture any geographic area, even off screen, with the property ScreenShots

20

// procedure call when bitmap ready
map.ScreenShots.OnScreenShot := doScreenShot ;

// you can change the size of the bitmap between each capture (default 800x600)
map.ScreenShots.Width := 2000;
map.ScreenShots.Height:= 2000;

// capture area centered on a point with a specified zoom
map.ScreenShots.ScreenShot(latitude,longiture, 16,'optional_name_of_capture');

// you can take screenshots even if the previous is not over yet

// Take the best zoom to a specific area
map.ScreenShots.ScreenShot(NorthEastLat, NorthEastELng, SouthWestWLat, SouthWestLng,'optional_name_of_capture');

// Take the best zoom to an area defined by its center and radius in km
// CAUTION use double for the radius, here 1.0 km, otherwise it will be mistaken for a simple zoom

map.ScreenShots.ScreenShot(Latitude, Longitude, 1.0 ,'optional_name_of_capture');


// when capture is ready, you go here
procedure TForm.doScreenShot(const name:string;const Screenshot:TBitmap);
begin
// don't free ScreenShot !
screenshot.SaveToFile(YourPath+name+'.bmp');
end;

The Photographer demo for Firemonkey shows you an example of using, you run 8 "drones" to photograph the ground every x meters.

Fig. 88 Photographer

go to page
© 2016 ESCOT-SEP Christophe - Made width Help&Web - RSS - Google+