Problem importing map shp/dbf
Problem importing map shp/dbf
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
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
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
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.
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 |
Instructions - How to post in this forum |
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
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
with many tryes with other program, different type of map saving and other things i have found the problem!!!!! but not the solution...
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???
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???
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
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.
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 |
Instructions - How to post in this forum |
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
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
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 :
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;
Pep Jorge
http://support.steema.com
http://support.steema.com
I have tried your procedure, but isn't what i'm searching for.
These images explain the result
With DeleteRepeatedPoints
Without DeleteRepeatedPoints
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?
These images explain the result
With DeleteRepeatedPoints
Without DeleteRepeatedPoints
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?
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.
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 ?
yes, you,re correct, each point in the Series correspond to a specific shape of a country, so these cannot be deleted as is.
I'm not able to reproduce this problem, I cannot see repeated value (Zimbawe) in all the shapes.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'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 ?
Pep Jorge
http://support.steema.com
http://support.steema.com
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
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
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 ?
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 ?
Pep Jorge
http://support.steema.com
http://support.steema.com
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
with this code
to load the TMemoryStream, and after that i use
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)
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);
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;
Code: Select all
LoadMap(Series1,TResourceStream(memorystream_shp),TResourceStream(memorystream_shx),Table1,'ISO_2','Z');
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?
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?
Pep Jorge
http://support.steema.com
http://support.steema.com