Recent

Author Topic: GIS Library for Lazarus  (Read 13115 times)

amir.eng

  • Jr. Member
  • **
  • Posts: 99
GIS Library for Lazarus
« on: January 10, 2022, 12:55:48 pm »
Hello guys,
First of all, thanks to everyone who created and is suportting this nice IDE.
I'm really interested to know if it's possible to read/write GIS Shape File via Lazarus ??

Already, I have done with C# and this library :
https://github.com/rosspickard/ArcShapeFile

It's great if I will do it with Lazarus like write Point or Polygon shapefile or read Polygon on form.
Lazarus 3.0 , FPC 3.2.2 , Windows 10 64, Excel 2016 64

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: GIS Library for Lazarus
« Reply #1 on: January 10, 2022, 01:17:04 pm »
If you're specifically talking about the files then I think the search term you need is ESRI.

There's various links in https://forum.lazarus.freepascal.org/index.php?topic=39392.0 which might be worth following up.

In general, I'd expect most libraries written in C to be fairly easily accessible.

Also https://sourceforge.net/directory/os:linux/?q=delphi+esri+shape where I see at least one interesting reference to Object Pascal.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

amir.eng

  • Jr. Member
  • **
  • Posts: 99
Re: GIS Library for Lazarus
« Reply #2 on: January 11, 2022, 08:56:42 am »
I had seen the topics before I posted. All the topics are old and I couldn't find any useful information. I just wanted to know if someone has ever experienced it in practical.
Lazarus 3.0 , FPC 3.2.2 , Windows 10 64, Excel 2016 64

stab

  • Full Member
  • ***
  • Posts: 234
Re: GIS Library for Lazarus
« Reply #3 on: January 12, 2022, 06:52:25 pm »
Hi,

I have a component TShapeObj that can read/write shapefiles, I can attach it, if you are interested.
As I live in Sweden, comments are moustly in swedish, but I guess you can figure out how to use it.
Maybe there is dependencies that I've not been aware of, but a starting point I think you can use it. :)

amir.eng

  • Jr. Member
  • **
  • Posts: 99
Re: GIS Library for Lazarus
« Reply #4 on: January 13, 2022, 03:06:52 pm »
Thank you so much. Yes I'm really interested to have it, please attach the component. I will try to figute out how to use it.

I also want to know, can I show shapefile and the attribute of the shapefile on the form with the component?
Lazarus 3.0 , FPC 3.2.2 , Windows 10 64, Excel 2016 64

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: GIS Library for Lazarus
« Reply #5 on: January 13, 2022, 03:58:03 pm »
My corona application contains a mode in which data are plotted in a map with countries colored according to their infection level. At first, I wanted to read shape files directly, but then I decided against it because of the many interrelated files. I found the kml format to be more appropriate because it has everything in a plain xml structure. For those cases where I did not find kml files I used the QGIS application to convert shp to kml. And, if I remember correctly, this program also helped me to reduce the number of the polygon points of the country boundary down to some decent level (forgot how I did this - this is a non-trivial task...).

For drawing the country shapes I used TAChart. The version in laz/main contains a new TPolygonSeries which was intended to become the ancestor of the country plots. But since I wanted to be able to compile the application also in older Lazarus versions I copied this code into the corona project (unit cPolygonSeries). There is another unit cGeoMap which interfaces to GIS data files, extracts the country boundary polygons and feeds them into a polygon series (a TcGeoMapSeries, to be precise, because it needs some ID to identify the countries). There's also a variety of projections to project the spherical coordinates onto the screen plane (Mercator, Miller, orthographic plus some more). A separate reader unit is specialized to get the data from the kml files (cGeoMapReaderKML). Basically the structure is intended to be independent of kml. So, when you write a reader for SHP according to what the KML reader does the program should be able to display SHP files as well.

The entire code probably is not general enough for all-purpose GIS plotting, but you may get an idea how a standard TChart could be used for this purpose.
« Last Edit: January 13, 2022, 04:00:28 pm by wp »

stab

  • Full Member
  • ***
  • Posts: 234
Re: GIS Library for Lazarus
« Reply #6 on: January 13, 2022, 04:08:45 pm »
Hi again,

Here it comes together with two other components:
worldviewportroutines - can be used to display world-coordinates in a display
WGS84                      - transformation between WGS84 and coordinates in
                                   national coordinate-system.
                                   constants in the beginning is for the national system
                                   in Sweden, but can be reassigned.
                           
Salutes
stab :)

stab

  • Full Member
  • ***
  • Posts: 234
Re: GIS Library for Lazarus
« Reply #7 on: January 13, 2022, 04:15:38 pm »
Forgot to answer your question:

Yes you can draw shapefiles in different colors on a canvas and have access to attributes

/stab

amir.eng

  • Jr. Member
  • **
  • Posts: 99
Re: GIS Library for Lazarus
« Reply #8 on: January 14, 2022, 11:16:25 pm »
Hi again,

Here it comes together with two other components:
worldviewportroutines - can be used to display world-coordinates in a display
WGS84                      - transformation between WGS84 and coordinates in
                                   national coordinate-system.
                                   constants in the beginning is for the national system
                                   in Sweden, but can be reassigned.
                           
Salutes
stab :)

I took a look at the components, ShapeObj component is incredible !!, it also has some Arcmap's tools such as Merge or Split shapefiles , add or delete field or getting centroid of a polygon.
I was also looking for a component to convert UTM coordinates to LatLong, now I have it. Many thanks for your favor.

Could you please give me a simple example to create Poylgon shapefile for these coordinates ?? :

1) x = 1569.84, y = 1430.57
2) x = 1018.21, y = 1103.42
3) x = 958.40, y = 1404

My next question, is it possible to use Select By Attribute with the component similar Arcmap ?? For example I want to use this select : Select * from BuildingShape where village= 'Kayakoy'

* Also thanks to wp for replying. I downloaded Corona software , it's a good idea but I needed all-purpose GIS component.

 
« Last Edit: January 14, 2022, 11:18:12 pm by amir.eng »
Lazarus 3.0 , FPC 3.2.2 , Windows 10 64, Excel 2016 64

stab

  • Full Member
  • ***
  • Posts: 234
Re: GIS Library for Lazarus
« Reply #9 on: January 15, 2022, 01:53:24 pm »
Hi again,

I'm somewhat busy right now, but I'll be back next weeks with description an how to create, read/write,  select and display shapefiles.
Have written TShapeObj according shapefile format and it has served my purposes well.  It is not optimized and when some new need has showed up it has been expanded. Anyone is welcomed to improve it.
As for your second question: It is possible to make the kind of selection your are asking for!

amir.eng

  • Jr. Member
  • **
  • Posts: 99
Re: GIS Library for Lazarus
« Reply #10 on: January 15, 2022, 09:25:57 pm »
Thanks a lot, I'm looking forward to your description or sample Lazarus project.
I hope to add Clip tool to the component. I saw Split function in the component but I don't know if that's the same Clip tool.

Split tool in Arcmap : Exporting shape files based on attribute field.
Clip tool in Arcmap : Exporting shape file based on another shape file (polygon shape).
« Last Edit: January 16, 2022, 07:45:20 am by amir.eng »
Lazarus 3.0 , FPC 3.2.2 , Windows 10 64, Excel 2016 64

stab

  • Full Member
  • ***
  • Posts: 234
Re: GIS Library for Lazarus
« Reply #11 on: January 17, 2022, 11:36:02 pm »
Hi,

Here comes a program showing a little about how to
use ShapeObj together with an instruction.

Both will be extended.

Regarding your thoughts about CLIP I would suggest that you look at Angus Johnson's  clipper.pas.
Look at attached unit: ClipperRoutines in which I've used clipper.pas to buffer a shapefile.

Found a bug in ShapeObj. A new version attached

 

amir.eng

  • Jr. Member
  • **
  • Posts: 99
Re: GIS Library for Lazarus
« Reply #12 on: January 18, 2022, 06:24:20 am »
Hi
Thank you for replying,
What is this error while compiling ?? :


« Last Edit: January 18, 2022, 06:30:36 am by amir.eng »
Lazarus 3.0 , FPC 3.2.2 , Windows 10 64, Excel 2016 64

stab

  • Full Member
  • ***
  • Posts: 234
Re: GIS Library for Lazarus
« Reply #13 on: January 18, 2022, 12:06:21 pm »
Excuse me, FastGeo is a library I've thought to perhaps use sometime.
The reference can be removed, because it is not currently used.

Following is from the description on the net:
FastGEO is a library that contains a wide range of highly optimized computational geometry algorithms and routines for many different types of geometrical operations such as geometrical primitives and predicates, hull construction, triangulation, clipping, rotations and projections.

That could also be something to consider when planning for a CLIP option.

stab

  • Full Member
  • ***
  • Posts: 234
Re: GIS Library for Lazarus
« Reply #14 on: January 19, 2022, 01:07:33 am »
Updated version of ShapeObjDemo with extended instructions.

Look at Split that have 2 variants
  One variant divides a shape with a straight line segment
  Another variant divides a shape with another shape.
  The second variant might correspond to Clip
  Note: not sufficiently tested

When selecting with a string field in attribute table the string
must be surrounded with ".

ShapeObj updated with comments in english
« Last Edit: January 19, 2022, 01:19:26 am by stab »

 

TinyPortal © 2005-2018