Recent

Author Topic: World map on a sphere.  (Read 16635 times)

RWC

  • Jr. Member
  • **
  • Posts: 92
World map on a sphere.
« on: August 27, 2016, 06:37:27 pm »
In my geographical project I’m using Circular’s DrawPolygonAntialias to draw a coastline of the UK & Ireland. This works brilliantly (& fast considering the number of TpointF’s involved). But I need the rest of the world too so this will probably be too much using polygons, plus I really would like to see the shaded terrain of the land & sea bed.

When testing the entries for the BGRABitmap contest I was astonished to see (in Lainz’s dragon) how fast a 3d object could be manipulated using so little code. (I understand small parts of this code).

Also in User137’s nxPascalDemo2 there is a wire-frame bounding sphere which rotates around it’s poles with mouse x movement and vertically from pole to pole with mouse y movement. This I exactly how I want to manipulate a globe. (This code seems complex & I understand almost none of it).

It seemed to me that if I could somehow create wire-frame model (or find a ready made one) and put a world map texture on it, Then I could create an obj file in the same format as Lainz’s ‘dragonwindspropicos.obj’

I’ve already downloaded a suitable shaded terrain world map of 10800x5400 pixel (106MB). Each pixel represents 2 minutes of arc in both north-south & east-west directions i.e. 30 pixel/degree. So I could use this easily with ‘SetPixel’ but probably too slow for mouse rotating.

Alternatively, Lainz made a demo that ran fast in a browser window (lainzdemo.7z). Could this method be used to plot points as an overlay over the Google map browser page (without having to learn google’s code)? And eliminate all the map imaging part of my project?

If any of these ideas seem feasible any help will be fantastic but please remember how little I know about Lazarus/FPC and this ol’ geezer may not have a lot of time for learning new tricks
( >:D  chemo! yuck O:-) but still smiling  :D).

Also, this is not a commercial project, just a tool I use (and for anyone else if they want it) so please don’t spend too much of your own precious time on replies. Many thanks, RWC.

p.s. @Lainz: I love the work you’re doing on Kaaj Controls. http://forum.lazarus.freepascal.org/index.php/topic,33744.0.html
The image looks very sleek, just like some expensive audio test equipment I once owned.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: World map on a sphere.
« Reply #1 on: August 27, 2016, 07:01:20 pm »
if I could somehow create wire-frame model (or find a ready made one) and put a world map texture on it
...
I’ve already downloaded a suitable shaded terrain world map of 10800x5400 pixel (106MB).
I'm afraid it's not as straight-forward to put a texture on a sphere. As far as you are working with a geographical project, you know of all the problems of different projections and coordinate systems. If you're looking for a quick and easy way, I'd better pick up something ready. You might want to look at: http://www.blendswap.com/blends/view/73957 or http://tf3dm.com/3d-model/planet-earth-99065.html or google for another ready model.
If you want to do your own model (e.g. in case you need really high resolution), it's also possible. Grab Blender editor and follow https://www.youtube.com/watch?v=X3aLlpSAaH4 .
If you only need to display the model I might suggest you using Castle Game Engine, you can make a simple viewer in 9 lines of code. See here: https://github.com/castle-engine/castle-engine/blob/master/examples/3d_rendering_processing/view_3d_model_basic.lpr#L37
However, I'm almost sure it can be done as easily in BGRA, you just need a ready model to.

Pay attention that the downloaded or made by Blender models can be "beautiful" but not geographically correct. If you really need geographical accuracy, you should do everything manually (that's gonna be hell of a work).
« Last Edit: August 27, 2016, 07:03:04 pm by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: World map on a sphere.
« Reply #2 on: August 27, 2016, 07:05:31 pm »

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: World map on a sphere.
« Reply #3 on: August 27, 2016, 07:11:56 pm »
Could this method be used to plot points as an overlay over the Google map browser page (without having to learn google’s code)? And eliminate all the map imaging part of my project?

This almost sounds like a job for a GIS. Which Google map are you referring to? Normally Google maps are projected in "Pseudo Mercator" (technically EPSG:3857). Bing and Apple maps have adopted this standard too. To plot, say, a point over a Google map, you would need to convert the point from longitude and latitude ("unprojected" geographic coordinate system) to Google's projection and then convert to the map coordinates (pixels).

Is your shaded terrain world map projected? Maybe if you could point to the source, I could take a look at it.

If you think you might need a GIS, please review Part 3 of this series and look at some of the screenshots:

https://dl.dropboxusercontent.com/u/28343282/MacXPlatform/PascalDynLibs.html

Also, a bit more detail of what you're trying to attempt might help. I'm confused as to whether you're trying to do 2D or 3D.

-Phil

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: World map on a sphere.
« Reply #4 on: August 28, 2016, 01:46:43 am »
But I need the rest of the world too so this will probably be too much using polygons,
Probably not exactly what you were looking for, but fpGUI includes a demo where the whole world is drawn on a globe. You can use the keyboard to rotate it up, down, left and right. You can zoom in and toggle the lon/lat grid lines on and off. See the <fpgui>/examples/apps/globe/ demo. All the polygon data is stored in the globe_data.inc file which is 24KB in size.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: World map on a sphere.
« Reply #5 on: August 29, 2016, 04:35:17 pm »
@Eugene: Very interesting reply – thank you.
Quote
I'm afraid it's not as straight-forward to put a texture on a sphere.
Texturing the sphere does look a bit hit&miss in the Blender demo. The ready made models look great but not quite the texture, lighting & resolution I need.
Quote
If you want to do your own model (e.g. in case you need really high resolution)…
That’s great. I found an interesting demo from your link, which just wrapped the image straight on the sphere without any tweaking? Maybe because it’s a geographical projection like the one I’m using so I’ll install Blender and give that one a try.
Quote
…models can be "beautiful" but not geographically correct…
Accuracy is not absolutely critical, my plotted points are the important bit. As long as I get a good indication of were I’m plotting I think that’ll be ok. Of course it would be even better to have precise mapping at my maximum zoom level but I’d need Gigabytes of data (which I expect will fit on a pin head soon!?).

Many thanks Eugene, that certainly gives me food for thought & exciting new things to try.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: World map on a sphere.
« Reply #6 on: August 30, 2016, 02:34:34 am »
Quote
I did this some time ago
@Lainz: Very nice model. This is a long shot but could that model be used in the lainzmixer project if I renamed ‘dragonwindspropicos.obj’ and copied mtl & png into that folder? I tried that way with 2 other obj files from ‘tf3dm.com’ but got just a white screen cycling light to dark to light etc.

Unfortunately I’m not receiving sketchfab’s confirmation email (address is correct & its not in the spam folder) so I can’t download your model yet. Edit: email confirmed now but model not downloadable.

Another issue I didn’t think through: I’m currently using BGRABitmap Layers for plotting points over the base map layer. I’m not sure how or even if layers work with BGRAScene3D, BGLVirtualScreen, BGRAOpenGL & BGRAOpenGL3D. I’ll look into that.

Many thanks for your help again Lainz, all the best.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: World map on a sphere.
« Reply #7 on: August 30, 2016, 02:41:13 am »
Quote
…fpGUI includes a demo where the whole world is drawn on a globe.
@ Graeme: You’ve clarified my confusion about fpGUI. I really like the look of Lainz’s Kaaj Controls but they needed fpGUI. Mistakenly thinking it was graphics program I was disappointed,
until now!
Now I have fpGUI 1.4.1 installed on Lazarus-1.4.2-fpc-2.6.4-win32 Vista (and will try later on lazarus-1.6.0-fpc-3.0.0-win32 Win7). This looks like another awesome piece of work Graeme.

Your Globe runs great. I love the Arrow Key control of yaw & pitch. I’ll borrow that idea if you don’t mind & looking at your code I may borrow some of those ideas too? The 1500+ data points display smoothly so I’ll try a low detail world with my current DrawPolygonAntialias which does the off screen clipping but polygons in the negative globe space are not needed so I should use your line segment method – it work well on the your example. On my UK map I manually removed the few broken polygons (part of Calais coast) & I load it via a stringlist to an array.
I use ‘geodas’ to extract a ‘mapgen.dat’ text file (lat & lon’s) from the NOAA shoreline data. Both links here:
http://www.effective-solutions.co.uk/getcoast.html
Thanks a lot Graeme – and I can try Kaaj Controls too now :)
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: World map on a sphere.
« Reply #8 on: August 30, 2016, 03:27:54 am »
Quote
I did this some time ago
@Lainz: Very nice model. This is a long shot but could that model be used in the lainzmixer project if I renamed ‘dragonwindspropicos.obj’ and copied mtl & png into that folder? I tried that way with 2 other obj files from ‘tf3dm.com’ but got just a white screen cycling light to dark to light etc.

Unfortunately I’m not receiving sketchfab’s confirmation email (address is correct & its not in the spam folder) so I can’t download your model yet. Edit: email confirmed now but model not downloadable.

Another issue I didn’t think through: I’m currently using BGRABitmap Layers for plotting points over the base map layer. I’m not sure how or even if layers work with BGRAScene3D, BGLVirtualScreen, BGRAOpenGL & BGRAOpenGL3D. I’ll look into that.

Many thanks for your help again Lainz, all the best.

Hi, I have that model with a higher resolution image too. I uploaded the preview to that website because some time ago I was selling the 3D model, BTW I will send you a PM with a copy of it.

I did that demo with help of circular, that was not easy as calling a loading function but he improved the bgrabitmap code for loading a 3d model and a texture with a single procedure.

You need the .obj .mtl and .png for example, the first of course is the model, the second is the material file and third is the bitmap of that model.

Also the .mtl at the end must have:
Code: Pascal  [Select][+][-]
  1. map_Kd dragonwindspropicos.png
  2.  
the map_Kd , most material files will not include it by default so you need to add it (the file I'm sending you by PM does not include it for example, you must add it).

Another thing is the zoom, is important to set it right, some models are too big and others too small, you need to figure if fits in the screen well.

And another thing is the resolution of the bitmap, if is too big it will not render! There is a texture resolution limit by OpenGL and by your graphics card (another example is the file i'm sending it by PM, the resolution is very high, but it works, just you need to change the format from tif to PNG).

Attached how the model I'm sending you looks with the lainzmixer demo.

With this changes, see the object name and the Scale method:

Code: Pascal  [Select][+][-]
  1.   inherited Create;
  2.   FetchDirectory := '.';
  3.   with FetchObject('earth.obj', True) do
  4.   begin
  5.     // Perfectly aligned with Blender 'Front view'
  6.     MainPart.RotateZDeg(180, False);
  7.     MainPart.RotateYDeg(180, False);
  8.     MainPart.Scale(3.5);
  9.   end;  

This model is realy very high res, it will be realy slow... well I've updated the model allowing Download in Sketchfab.

BUT if you can download the file I'm sending you by PM is has the .blend model that you can tune and set a different ammount of subdivisions with the subsurf modifier. For example if you set it to 0 and export the model will be like low poly but will run really fast in the lainzmixer demo. Try different values of subsurf and that's all.

Well here it is, anyone can dowload in Sketchfab or here, no annoying PM :)
https://mega.nz/#!6F8jRDjI!McHcRboueCF6n41fVEkzG54z9-NIhOolNUa_X-dMVt8
« Last Edit: August 30, 2016, 03:34:24 am by lainz »

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: World map on a sphere.
« Reply #9 on: August 31, 2016, 07:17:39 pm »
Quote
This almost sounds like a job for a GIS.
@Phil: Apologies for the delayed reply, I’ve been studying GIS. As a novice I’m always worried about messing up my Lazarus setup so I may install a 2nd copy & do a trial install. I’m looking forward to seeing the Pascal Library docs & code but I still need to work out which GDAL unit & other dependencies I need on my window PC. Previously I’ve only used fGIS & Geodas desktop apps for extracting shorelines from shapefiles but to have access from Lazarus will be fantastic. Many thanks Phil, I’ll let you know how I get on. BTW my shaded terrain world map is geographical. Each pixel is a lat/lon point for every ½ degree NSEW. Downloaded from:
http://naciscdn.org/naturalearth/50m/raster/NE2_50m_SR_W.zip

Quote
Which Google map are you referring to?
google.co.uk/maps/ . The spark of the idea was another demo by Lainz (in jscript) which draws on a browser page using BGRABitmap. Plus the thought of using not only google’s vast map resource, but also their clever management of images at different scale. I imagined a transparent layer for plotting my points over the google map thus bypassing memory & image management problems.

Obviously I didn’t think it through properly and as you say, I would have to match the Pseudo Mercator projection but more importantly, without access to google’s data the user would have to type the overlay co-ordinates into the search box & zoom to match the scale. So, not a very practical idea in retrospect. That is unless one of the Pascal libraries for GIS can gain access to scale & viewpoint from Google, Bing or Apple maps or better still, access the high-res maps;)
Quote
Also, a bit more detail of what you're trying to attempt might help. I'm confused as to whether you're trying to do 2D or 3D.
You’re right, I should have said something like: ‘in a 3d environment’ & added the link to the screenshots on the Graphics Contest page too: http://forum.lazarus.freepascal.org/index.php/topic,32626.45.html

Essentially I’m plotting grand circles & arc segments on a spherical representation of the Earth. It can be rotated around it’s poles & vertically from North to South pole like Graeme’s globe above. I wrote my own code years ago to calculate x,y,z and lat/lon values and recently I’ve converted some java code from the internet to add more options such as the intersect point of arc segments.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: World map on a sphere.
« Reply #10 on: September 01, 2016, 01:48:50 am »
I’ve been studying GIS.

I believe GIS could provide several solutions for what you're trying to do with Natural Earth rasters, maps, etc.

Solution 1. Download and install QGIS (qgis.org). Add your Natural Earth .tif as a layer. Now you can pan and zoom, add an overlay using a shapefile of coastal points, etc.

Solution 2. If you want to use a Web-based map service instead of a large local file, install the QGIS OpenLayers and QuickMapServices plugins. Now on the Web menu you can add a map from Google, Bing, Apple, OpenStreetMap (Mapnik), NASA, Landsat, etc. Now overlay this map with your coastal shapefile.

With both 1 and 2, save the settings in a QGIS project file (.qgs) so you don't have to repeat any steps the next time - just open the project file in QGIS. With 2, all you would need to distribute to other users would be the project file and any shapefiles of your own. Note that QGIS would also be a cross-platform solution (Win, Mac, Linux).

Also, you can write your own QGIS plugins if you want to add some programming (in Python) to your projects. These plugins can be downloaded and installed by users similar to the way the OpenLayers and QuickMapServices plugins are done.

Solution 3. Since QGIS includes GDAL, just add its location to your system path. Now install the P4G GIS controls in Lazarus and create a Lazarus app with a legend and map control. Programmatically add your Natural Earth raster file as a map layer and any vector (shapefile) layers you want. See the PasCast example app.

Ideal solution (not possible currently) would be to stream in a map from Google, etc. with #3 instead of using a local file, but there is no suitable Pascal control to do that.

To program something like that, though, you could create a Web app, using a Pascal backend and JavaScript or ASP.NET for the map and UI in the browser (see the QxCast and AspCast examples).

-Phil



avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: World map on a sphere.
« Reply #11 on: September 02, 2016, 11:34:29 am »
Ideal solution (not possible currently) would be to stream in a map from Google, etc. with #3 instead of using a local file, but there is no suitable Pascal control to do that.
Maybe TMapViewer could be used as part of such a solution:
http://forum.lazarus.freepascal.org/index.php/topic,12674.0.html
https://code.google.com/archive/p/mapviewer/source/default/source
« Last Edit: September 02, 2016, 12:34:31 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: World map on a sphere.
« Reply #12 on: September 02, 2016, 12:38:18 pm »
@avra:
I was just about to say the same thing. I have code from 2013 for a unit kcMapViewer.pas (TMapViewer component) created by Maciej Kaczkowski. It does just that. It renders maps from the Internet based on Google Maps, OpenStreetMaps and I think Bing. Unfortunately the code I have doesn't have a readme file or repository URL, so I have no idea where I actually downloaded this from. :-/

Edit:
Ah, a quick Google search and I found the homepage:  http://keit.co/p/tmapviewer/
« Last Edit: September 02, 2016, 12:41:29 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

PaulFMichell

  • New Member
  • *
  • Posts: 21
Re: World map on a sphere.
« Reply #13 on: September 02, 2016, 12:54:20 pm »
I don't know if this might be of interest:

http://michellcomputing.co.uk/blog/2016/03/natural-earth-data/

It is an off-line globe control using the Natural Earth data set with a higher resolution coastline inserted for the UK and Ireland.  I wrote this as part of the Ordnance Survey's new Grid InQuest II software (written using Free Pascal and Lazarus) which is now OpenSource, available here:

https://bitbucket.org/PaulFMichell/gridinquestii

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: World map on a sphere.
« Reply #14 on: September 02, 2016, 03:57:03 pm »
Ideal solution (not possible currently) would be to stream in a map from Google, etc. with #3 instead of using a local file, but there is no suitable Pascal control to do that.
Maybe TMapViewer could be used as part of such a solution:

The key here is "suitable". TMapViewer is undocumented, has a viral license if you use it your program, and is basic abandonware.

 

TinyPortal © 2005-2018