Geocoding V

Max Kleiner
Nerd For Tech
Published in
3 min readMar 21, 2024

Have you ever come across a dataset having addresses like below?

location, lat, long, maplink
“Place Grévy, Azans, Dole,”,47.094812599999994,5.4972803,geocode_dole_layer1714069.png
“Place Grévy, France, Dole,”,47.094812534546784,5.4972988,geocode_dole_layer1675941.png

This is the third step story of Geocoding namely

  1. Get coordinates of an location (address)
  2. Show a map of location interest
  3. Store the data in a fast csv file

As you may konw Geocoding is the process of converting addresses or locations into geographic coordinates (i.e. latitude and longitude) and Reverse Geocoding is the process of converting geographic coordinates (latitude & longitude) into a human-readable address. Then services like mapbox or OpenStreetMap provide APIs which can be used by anyone. First we start with two constants:

Const
GEOCSV_BASE = ‘geocoding61_12_base.txt’;
GEO_LOCATION = ‘1 Place Grevy, Dole, France’;

Then we call our first function:

latlong:= TAddressGeoCodeOSM5(GEO_LOCATION);

and we get as Json description OSM (OpenStreetMap) res back_:

Coords: lat 47.09481 lng 5.49728 1, Place Grévy, Azans, Dole, Jura, Bourgogne-Franche-Comté, France métropolitaine, 39100, France place_id: 111925270
get geocoords: lat: 47.0948 — lon: 5.4973

The Get API looks like the following:

TAddressGeoCodeOSM5 pass: https://nominatim.openstreetmap.org/search?format=json&q=1%20Place%20Grevy,%20Dole,%20France
Check Url: 200

Next we call

GetGeoInfoMap5(latlong.lat,latlong.long,15,850,’yourAPIKey’, ExePath+’examples\geocode_dole_layer5.png’, true);

and get a map

Dole Hôtel de la Cloche

Parameter 15 is zoom-factor and 850 the size of the png-graphic. The script you find at: softwareschule.ch/examples/geocoding7.txt

As the last step we store the data in a CVS file:

acsv:= TJvCSVBase.create(self);
FieldNames:= TStringList.create;
fieldnames.add('location')
fieldnames.add('lat')
fieldnames.add('long');
fieldnames.add('maplink');
if not fileExists( exepath+GEOCSV_BASE) then
acsv.DataBaseCreate(exepath+GEOCSV_BASE, fieldnames, false, true) else begin
acsv.DataBaseOpen(exepath+GEOCSV_BASE);
//writeln(acsv.CSVFieldNames[0])
acsv.recordnew;
acsv.CSVFieldNames[0]:= 'Place Grévy, Azans, Dole,';
acsv.CSVFieldNames[1]:= flots(latlong.lat);
acsv.CSVFieldNames[2]:= flots(latlong.long);
acsv.CSVFieldNames[3]:= 'geocode_dole_layer'+IBRandomString(7)+'.png';
acsv.Recordset(acsv.CSVFieldNames, false);
//acsv.recordpost;
//acsv.DisPlayFields
acsv.DataBaseClose;
end ;
acsv.free
fieldnames.free;
openfile(exepath+GEOCSV_BASE);

and get a dataset file like above.

JvCSVBase, a collection of components for handling CSV database files, was created by JanSoft. It includes five components: TjvCSVBase, TjvCSVEdit, TjvCSVComboBox, TjvCSVCheckBox, and TjvCSVNavigator. These components in maXbox5 allow you to create, restructure, browse, and edit CSV database files without any programming12. If you’re working with CSV data, JvCSVBase provides a convenient way to manage it within your script applications.

Then we do at a forth last step some unit tests with reverse geocoding:

Testunit From Cologne to Graz, Bern and St. Ingbert and Dole
get geocoords: lat: 50.9473 — lon: 6.9503 Cologne
get geocoords: lat: 47.0739 — lon: 15.4168 Graz
get geocoords: lat: 46.9479 — lon: 7.44744 Bern
get geocoords: lat: 49.2709 — lon: 7.11161 St. Ingbert
get geocoords: lat: 47.0948 — lon: 5.49728 Dole

Testcall OpenWeb(‘https://www.latlong.net/c/?lat='+flots(latlong.lat)+'&long='+flots(latlong.long));

maplink: https://maxbox4.files.wordpress.com/2024/03/1277_geocode_dole_layer5.png

Max Kleiner 21/03 2024

To execute and test the script you need 3 steps:

  1. Download the box and start maXbox5.exe: https://github.com/maxkleiner/maXbox4/releases/download/V4.2.4.80/maxbox5.zip
  2. Load the script_: softwareschule.ch/examples/geocoding7.txt
  3. Press compile or F9 to run it!
CC 6574 Dole
TEE 5 Nations Locs SNCF-DB-SBB-FS-ÖBB

When you travel you need sure a map and then transportation and weather too. So we put these services together, safe, solid and sustainable:

softwareschule.ch/examples/geocoding8.htm

Directions at work
Directions at Work II
Script 1274_GoogleDirForm2GeocodeWeather_General.pas
Weather in embedded browser

--

--

Max Kleiner
Nerd For Tech

Max Kleiner's professional environment is in the areas of OOP, UML and coding - among other things as a trainer, developer and consultant.