Problem importing map shp/dbf

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Problem importing map shp/dbf

Post by sicorspa » Thu Jan 15, 2009 7:37 am

Hi all,
I have a little problem to understand how is linked the data from DBF file to SHP file.
I have downloaded World Map from this site. From this download I received five files, SHP, SHX, SBN, SBX and DBF.

I think the only that i need is SHP, SHX (to load the chart) and DBF (to get the name of the shapes/countries).

The main problem is that I have correctly loaded SHP and SHX on a TeeChart, and they are visualized correctly, but the problem is with DBF, because the DBF have 239 record, but TeeChart recognize over 900 shapes.

I have tryed with many other software and all recognize 239 shapes from SHP, the same of DBF file, so i can link 1 to 1 the record, but with TeeChart this is impossible.

Am I doing something wrong? There is a option on series or chart that i'm missing?

Please help because i need to have a world map with country names/iso values to insert my data (if it's possible also with standard integrated world map of teechart it will be better, but the standard wolrd map of teechart have more than 2500 shapes and many with no names, and also no iso values).

Many thanks
Manuel

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Jan 15, 2009 8:39 am

Hi Manuel,

Have you tried loading maps as in the TeeMaps demo at C:\Program Files\Steema Software\TeeChart 8.04 for Delphi 2009\Examples\TeeMaps?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Post by sicorspa » Thu Jan 15, 2009 11:01 am

i'm using Delphi 7 (i missed to say) and i have tryed the demo and looked insight, but in the demo if i check "Use dbf table" won't work, the Text field remain blank.

I also checked the code but something missing, like:

-am i wrong or the Edit1.Text and Edit2.Text (Text and value field) isn't used? so i can't change the value to try if dbf file is working

-how is possible to use a 251 row table (world.dbf) in a 2136 shape table? infact the dbf in example isn't working at all in the map series

-where is located the resource file with the map loaded in the example? is precompiled inside a unit? this because if i use the function LoadMapFromResource with my correct resource value i get "resurce not found", i must use the LoadMap function, creating first a TMemoryStreamand after cast it as TResourceStream and pass this in input to LoadMap.

Howether, speaking of my test program, using LoadMap i have tryed to pass also the TTable with dbf data and name and value field.
All data is correctly loaded but, as i say, teeChart see about 1250 shapes and i have only 239 entries in the DBF, so the first 239 shapes have a name (wrong because of the order) and the other have all Zimbawe that is the last record in dbf file.
But the strange thing is that many other program like Shape Viewer see 239 shapes, infact if i use the function "Create empty dbf file" with Shape Viewer it creates a 239 row file.


So, finally, shp file is correctly loaded (graphically speaking) but there are too much shaper recognized and many other program with the same .shp shot the correct shape number


No one have seen this problem before?

Many thanks and sorry for my english :oops:

sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Post by sicorspa » Thu Jan 15, 2009 11:13 am

with many tryes with other program, different type of map saving and other things i have found the problem!!!!! but not the solution... :oops:

the map i have downloaded is using poligon and have 239 of them.

i have saved with an online utility in polyline format, and show 1256 polyline, exacly the same that teeChart recognize.


now, am i wrongly loading the shp with poligon file (like i must use a parameter to specify the map shape type or something else) or does teeChart translate any type of shape in polyline automatically??? :?: :?:

sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Post by sicorspa » Thu Jan 22, 2009 12:40 pm

noone have any advice or have noticed similar problem??

many thanks
Manuel

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Jan 26, 2009 10:37 am

Hi Manuel,

Sorry for the delayed reply, we missed that one.

If you are a TeeChart sourcecode customer you can have a look at TeeSHP.pas. There you can see how shape files are loaded in LoadMap method, depending on the shape type.

If you are not a sourcecode customer please send us the shp file you are trying to load and we will debug it here. You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Post by sicorspa » Mon Jan 26, 2009 12:43 pm

i have uploaded in the upload page world_countries_shp.zip file, with my nick name. This is the version with 239 poligons, as you can see with any application like "shape viewer" (a free application)

this is the file downloaded in the link in the first post.

if you want i can upload the same shp saved via a web applet with polylines, that have exactly 1256 polyline as teechart recognize instead the 239 poligons.

Many thanks
Manuel

sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Post by sicorspa » Mon Jan 26, 2009 12:45 pm

i forget to say that i haven't the source code, for that reason i have uploaded the file

Thanks

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Jan 27, 2009 11:14 am

Hi Manuel,

first of all, sorry for delay with the answer.
I've been doing some tests here, and all the related with shp file and dbf is working fine, I mean the data is loaded without errors and shapes are correctly displayed.
The thing I noticed, as you said in your previous posts, is that it generates a lot of Series points instead of just the 239 points that should be created. This is because polyline and polygon points are treated in the same way. To correct this we have to modify the code of the TeeSHP.pas file in order to add single points and not the same one for each part the shape has.
I've added this on our wish list to be considered for the next releases of the TeeChart Pro vcl version.

A solution for the moment, in case you don't want to have repeated points into the Series would be to remove them once the shp file has been loaded, using the following code :

Code: Select all

procedure TForm1.DeleteRepeatedPoints;
var i : integer;
begin
    i := 1;

    while i < Series1.Count-1
    do
      if (Series1.ZValue[i] = Series1.ZValue[i-1]) and (Series1.Labels[i]=Series1.Labels[i-1]) then
         Series1.Delete(i)
      else
          inc(i);
end;

sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Post by sicorspa » Tue Jan 27, 2009 1:05 pm

I have tried your procedure, but isn't what i'm searching for.

These images explain the result


With DeleteRepeatedPoints

Image


Without DeleteRepeatedPoints
Image

The problem is that TeeChart load the DBF table, but repeat the last value (Zimbawe) in all the shapes over 239, so your procedure delete them all.

If i doesn't load the table the procedure doesn't delete anything.

Howether the names loaded from DBF weren't link to the right shape because of the wrong number of shapes, so it's impossible to delete the shapes with the same Z value (empty value) without the possibility to link the correct shape to the correct DBF record.


An example is the default europe map, where Denmark has 3 or 4 different shapes instead of 1 (because of the island and other), so I haven't only one record in the series for Denmark to direct link the value, and if I try your procedure with this map probably I will get a "cutted" Denmark.

Am I right?

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Wed Jan 28, 2009 10:46 am

Hi Manuel,

yes, you,re correct, each point in the Series correspond to a specific shape of a country, so these cannot be deleted as is.
The problem is that TeeChart load the DBF table, but repeat the last value (Zimbawe) in all the shapes over 239, so your procedure delete them all.
I'm not able to reproduce this problem, I cannot see repeated value (Zimbawe) in all the shapes.

I've just send one example directly to your mail which seems to load data from your shp and dbf files correctly. Would you be so kind to test it and let me know how can we see the problem here ?

sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Post by sicorspa » Wed Jan 28, 2009 12:40 pm

ok, with your program all works fine, but you load the map directly from the file world_countries_shp.shp.

I have tried a different call to LoadMap, because I need to embed the map in a resource file; this file have the shp and shx inside

I load all in 2 MemoryStream (because with ResourceStream I always get 'Unable to locate world_countries_shp.shp' error)

After loaded that, I call LoadMap with TResourceStream(mymemorystream_shp) for the shp argument and the same for the shx one.

The dbf is loaded with the direct path to disk as Database Name, and its name as table name (like your example).

Doing this i have the problem descripted before.

Is it possible that using as argument of LoadMap "TResourceStream(mymemorystream_shp)" i lose some data?

Many thanks

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Jan 30, 2009 4:10 pm

Hi Manuel,

it's strange that it gives you an error trying to load from the resource file. Would you be so kind to send us the .res file you're using to be able to check it here ?

sicorspa
Newbie
Newbie
Posts: 43
Joined: Tue Jan 13, 2009 12:00 am

Post by sicorspa » Fri Jan 30, 2009 5:22 pm

the error i get is not from resource file but from LoadFromResource function of TChart

i have uploaded resource.RES file, maked with BRCC32 of Delphi7 with the resource.rc like this

mappashp SHP "mappashp.shp"
mappashx SHX "mappashx.shx"
mappadbf2 DBF "mappadbf2.DBF"
mappasbx SBX "mappasbx.sbx"
mappasbn SBN "mappasbn.sbn"

inside i have putted also the sbx and sbn file but never used them

the other files are the same as the files uploaded before, renamed from world_countries_shp to these names.


i use this function

Code: Select all

 LoadResourceFile('mappashpl.shp', memorystream_shp);
 LoadResourceFile('mappashpl.shx', memorystream_shx);
with this code

Code: Select all

procedure TForm1.LoadResourceFile(aFile:string; ms:TMemoryStream);
var
   HResInfo: HRSRC;
   HGlobal: THandle;
   Buffer, GoodType : pchar;
   I: integer;
   Ext:string;
begin
  ext:=uppercase(extractfileext(aFile));
  ext:=copy(ext,2,length(ext));
//  if ext='HTM' then ext:='HTML';
  Goodtype:=pchar(ext);
  aFile:=changefileext(afile,'');
  HResInfo := FindResource(HInstance, pchar(aFile), GoodType);
  HGlobal := LoadResource(HInstance, HResInfo);
  if HGlobal = 0 then
     raise EResNotFound.Create('Can''t load resource: '+aFile);
  Buffer := LockResource(HGlobal);
  ms.clear;
  ms.WriteBuffer(Buffer[0], SizeOfResource(HInstance, HResInfo));
  ms.Seek(0,0);
  UnlockResource(HGlobal);
  FreeResource(HGlobal);
end;
to load the TMemoryStream, and after that i use

Code: Select all

LoadMap(Series1,TResourceStream(memorystream_shp),TResourceStream(memorystream_shx),Table1,'ISO_2','Z');
With this code i have the first 239 shapes with a wrong ISO code (because in aplhabetical order the ISO codes were loaded for the first 239 shapes) and after that i get all the other shapes with ZW code (the last ISO code of the table)

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Feb 03, 2009 11:00 pm

Hello Manuel,

I’ve been trying to get the same problems here by using the res file, but I cannot use it as was a 16bits resource. I’ve recreated a new .rc and .res file from your shp, shx, etc… files and now I all seems to work fine using the LoadMapFromResource method. I’ve just sent an example directly to your mail which shows both options (loading from res and from shp and dbf directly).

Does it works fine for you?

Post Reply