Lazarus

Programming => General => Topic started by: amir.eng on January 10, 2022, 12:55:48 pm

Title: GIS Library for Lazarus
Post by: amir.eng 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.
Title: Re: GIS Library for Lazarus
Post by: MarkMLl 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
Title: Re: GIS Library for Lazarus
Post by: amir.eng 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.
Title: Re: GIS Library for Lazarus
Post by: stab 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. :)
Title: Re: GIS Library for Lazarus
Post by: amir.eng 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?
Title: Re: GIS Library for Lazarus
Post by: wp on January 13, 2022, 03:58:03 pm
My corona (https://github.com/wp-xyz/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.
Title: Re: GIS Library for Lazarus
Post by: stab 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 :)
Title: Re: GIS Library for Lazarus
Post by: stab 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
Title: Re: GIS Library for Lazarus
Post by: amir.eng 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.

 
Title: Re: GIS Library for Lazarus
Post by: stab 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!
Title: Re: GIS Library for Lazarus
Post by: amir.eng 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).
Title: Re: GIS Library for Lazarus
Post by: stab 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

 
Title: Re: GIS Library for Lazarus
Post by: amir.eng on January 18, 2022, 06:24:20 am
Hi
Thank you for replying,
What is this error while compiling ?? :


Title: Re: GIS Library for Lazarus
Post by: stab 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.
Title: Re: GIS Library for Lazarus
Post by: stab 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
Title: Re: GIS Library for Lazarus
Post by: amir.eng on January 19, 2022, 06:31:42 am
Great, I check it out and also tools.

Few issues:

-Parcels border are not clear when Outline mode is diabled (Please take a look at the attached image, the left shape file is in Arcmap and the right one is the same shape file in the Application)
-Is it possible to add Zoom In and Zoom Out to the main shape view window?
-Is it possible to select feature by clicking on the main shape veiw window and showing only the feature's attributes on the shapetable ?
Title: Re: GIS Library for Lazarus
Post by: zamtmn on January 19, 2022, 08:55:09 am
There is also such an variant, it does not directly supports SHP, but a lot has been done in it for fast processing of vector graphics
Title: Re: GIS Library for Lazarus
Post by: stab on January 20, 2022, 12:04:08 am
Regarding your question:
Is it possible to select feature by clicking on the main shape veiw window and showing only the feature's attributes on the shapetable ?

Should I understand this so:
 you would like that only attributes for selected shape is displayed?

Regarding border not clear:
  Have to look at that little more

Working on zoomin, zoomout and pan
Title: Re: GIS Library for Lazarus
Post by: loaded on January 20, 2022, 08:18:58 am
-Parcels border are not clear when Outline mode is diabled (Please take a look at the attached image, the left shape file is in Arcmap and the right one is the same shape file in the Application)
Regarding border not clear:
  Have to look at that little more

By the way, I can say with the experience I gained from a CAD application that I designed in Android Studio, the backbone of which I wrote with Lazarus+LAMW;
Defining the brush and pen colors separately will solve the problem.

Related application usage test video;  (https://youtu.be/gBS0AMrJ50s)
Title: Re: GIS Library for Lazarus
Post by: amir.eng on January 20, 2022, 11:56:55 am
Regarding your question:
Is it possible to select feature by clicking on the main shape veiw window and showing only the feature's attributes on the shapetable ?

Should I understand this so:
 you would like that only attributes for selected shape is displayed?

Regarding border not clear:
  Have to look at that little more

Working on zoomin, zoomout and pan
Yes I mean the table shows only attribute for selected shape like Arcmap.
Could you please add zoomin, zoomout,pad, selecting feature by mouse ??
Title: Re: GIS Library for Lazarus
Post by: stab on January 20, 2022, 12:43:05 pm
Regarding selecting feature by mouse, you have it already, just check HitTest and click in a shape. In the version you have right now, all features will show up, but current attribute is marked. I've a new version where just attributes for the selected is shown.
Working on  zoomin, zoomout,pan and your problem with somewhat jagged borders.
Title: Re: GIS Library for Lazarus
Post by: stab on January 26, 2022, 06:48:04 pm
Have been testing quite a bit to achieve fast drawing, am not satisfied but
think someone smarter than me have to fix that.

You now have zoom, pan and antialiasing.

Included in the zip file is a new component ShapeObBGRA that draws on a
TBGRAGraphicControl that handles antialiasing and removes jagged borders.

If you or someone else improves the component I'd be glad to have a copy.
Title: Re: GIS Library for Lazarus
Post by: winni on January 26, 2022, 07:43:20 pm
@stab

Hi!

You forgot the dir auxiliary with the file shapeobjbgra.pas  in your zip file.

Winni
Title: Re: GIS Library for Lazarus
Post by: stab on January 26, 2022, 10:04:23 pm
Sorry, new zip file included test shapefile :o
Title: Re: GIS Library for Lazarus
Post by: winni on January 27, 2022, 12:04:00 am
Hi!

First shot:

Code: Text  [Select][+][-]
  1. ShapeObj.pas(5595,58) Error: Call by var for arg no. 5 has to match exactly: Got "Double" expected "Extended"
  2.  

On Linux64

Winni
Title: Re: GIS Library for Lazarus
Post by: stab on January 28, 2022, 02:03:05 pm
As I wrote earlier:
Have written TShapeObj according the shapefile format description 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 welcome to improve it. If so, I'm interested in getting a copy.
TinyPortal © 2005-2018