Page 1 of 2

Limiting polygons from a shapefile

Posted: Wed Jul 15, 2009 4:49 pm
by 10549917
I need to limit the polygons shown from an ESRI shapefile plotted as a MapSeries i.e. I don't want to plot all the polygons included in the shapefile, only some of them. How do I achieve this?

I use TeeChart 8.0.1 with Delphi 2006.

Thanks
Bruce

Re: Limiting polygons from a shapefile

Posted: Thu Jul 16, 2009 10:18 am
by yeray
Hi Bruce,

You could delete the polygons you don't want to be drawn:

Code: Select all

Series1.Shapes.Delete(index);

Re: Limiting polygons from a shapefile

Posted: Thu Jul 16, 2009 1:11 pm
by 10549917
Thanks. By Index, do you mean the objectid in the shapefile?

Bruce

Re: Limiting polygons from a shapefile

Posted: Thu Jul 16, 2009 2:30 pm
by yeray
Hi Bruce,

Yes, the index is the number assigned in the list of items. From 0 to numberOfItems-1.

Re: Limiting polygons from a shapefile

Posted: Thu Jul 16, 2009 4:25 pm
by 10549917
Thanks

Re: Limiting polygons from a shapefile

Posted: Fri Jul 17, 2009 8:00 am
by 10549917
Sorry, still can't get this to work. I manage to delete some of the polygons but they are not the correct ones. How do I identify which polygons I want to keep and which not? At present I load the shapefile with
LoadMap(Series4,tmp3,dmPGC.cdsPolygons,MapFieldName,MapValueFieldName,true);
where tmp3 is the shapefile name (I get all the polygons in this file)
dmPGC.cdsPolygons contains the OBJECTID's for each polygon
MapFieldName does not seem to store its contents anywhere
MapValueFieldName stores its contents in the Value field (I can see this with a chartgrid)

All X and Y values are zero.

If the Delete method worked, I should only see the single ObjectID in the Value column of the grid but,after repainting, I still see all values but only some are associated with polygons and I can't tell which.

Any suggestions would be much appraciated

Bruce

Re: Limiting polygons from a shapefile

Posted: Fri Jul 17, 2009 10:07 am
by yeray
Hi Bruce,

Could you please attach here a simple example we can run as-is to reproduce the problem here? This could help us to understand what are you exactly trying to do and to look for a solution for you.

Thanks in advance.

Re: Limiting polygons from a shapefile

Posted: Tue Jul 21, 2009 9:44 am
by 10549917
Can you send me details for an offline email address or ftp site. Unfortunately, the smallest version of example geodatabase that I can create is about 18 Mb and this is needed for the program. The rest of the code, etc is quite small, as is the shapefile but I need to draw information from the geodataabse too.

Bruce

Re: Limiting polygons from a shapefile

Posted: Tue Jul 21, 2009 9:52 am
by yeray
Hi Bruce,

We don't have any platform you could use to send us a so heavy file. I recommend you to send it through rapidshare or yousendit. And if you don't want to publish this for everybody, you could send us the url provided to us through info@steema.com

Re: Limiting polygons from a shapefile

Posted: Wed Jul 22, 2009 10:40 am
by yeray
Hi Bruce,

Thank you for the project but it would take us a lot of time to debug and understand what exactly should show each of the 6 Chart Grids, the 4 charts and dozens of ADO components. I recommend you to try to identify the exact problem you are suffering and arrange a simple example project we can run as-is here to reproduce it here.

Re: Limiting polygons from a shapefile

Posted: Wed Jul 22, 2009 6:11 pm
by 10549917
Hi Yeray
okay, I accept what you say although there were only two procedures in what I sent that actually were relevant. Others were to show what data was in the tables.

I have created a smaller, more directed program which uses the same geodatabase and shapefile. I will send it by regular email as I can't upload any variant of .exe via the forum.

Some specifics that you should check are:

1) after opening the database (File Open database) and then loading the shapefile (File Load Shapefile), you will note that there are two records with objectid 959 in the chartgrid. There is only one in the original data source.
2) Click on File - Deleted unwanted polygons and step through the polygons one by one as they are deleted. Note that objectid 962 is supposedly deleted several times even though it only exists once. This seems to be because the polygon record is not actually deleted from the series, it is just set to not show. Thus, as a result as I step through the index of Z values in the series I keep finding values which have supposedly been deleted. The index value is now associated with a different polygon but a record with the original Z value still exists. Hence the wrong polygon gets deleted.

Thanks
Bruce

Re: Limiting polygons from a shapefile

Posted: Tue Jul 28, 2009 6:41 pm
by 10549917
Yeray
something that struck me a while after posting my previous response was that, if you keep each record in the TeeChart dataset (however it is done), I could conceivably achieve what I need by hiding shapes I don't want and showing only those I do, rather than what I have been attempting which is to delete the ones I don't want.

Is this an option and if so, how do I control visibility of individual shape polygons?

Bruce

Re: Limiting polygons from a shapefile

Posted: Wed Jul 29, 2009 2:25 pm
by yeray
Hi Bruce,

We could reproduce the problem of the number of polygons loaded with a really simpler example with only a chart and a chartgrid in a form:

Code: Select all

procedure TfPGC_mn.FormShow(Sender: TObject);
var
  tmp3 : string;
begin
  tmp3 := 'c:/Program Files/EIMT/Paleogis/beTestPolygons.SHP';
  try
    LoadMap(Series3,tmp3);
  finally
  end;
  Series3.ColorEachPoint := true;
  //Series3.SetNull(1);
  //Series3.Pen.Visible:=false;
  ChartGrid1.Repaint;
end;
For some reason there are 14 polygons loaded when ShapeViewer clearly says that there should be 13 polygons in that .shp file. And the value for the second and the third polygons is always the same. So I've added it to the wish list to be revised for further releases.

On the other hand, if it helps, we could see that setting a point to null and deactivating the whole series pen, it looks like if it had been deleted.

Re: Limiting polygons from a shapefile

Posted: Wed Jul 29, 2009 6:42 pm
by 10549917
Thanks Yeray.

The approach to hide or show shapes will work fine for my application. However, in testing this I have encountered some additional problems.

1) If one has two charts, each with a mapseries (in my case series3 and series4), when one loads the second mapseries data from a shapefile (I load the same shapefile into both charts), the second mapseries loaded always ends up with the same MapFieldName and MapValueFieldName values for all records.
2) If I reload the same shapefile into a mapseries the same happens.

This should not be the case, especially when the last option in LoadMap is set to true.

Regards
Bruce

Re: Limiting polygons from a shapefile

Posted: Thu Jul 30, 2009 9:10 am
by yeray
Hi Bruce,

I'm not sure to understand this problem. Here is the code I used to try to reproduce it. Could you please modify it until we can reproduce it?

Code: Select all

uses TeeMapSeries, TeeSHP;

var Series1, Series2: TMapSeries;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := false;
  Chart2.View3D := false;

  Series1 := TMapSeries.Create(self);
  Chart1.AddSeries(Series1);
  Series2 := TMapSeries.Create(self);
  Chart2.AddSeries(Series2);

  Series1.ColorEachPoint := true;
  Series2.ColorEachPoint := true;
  series1.UseColorRange := False;
  series2.UseColorRange := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  tmp : string;
begin
  tmp := 'beTestPolygons.SHP';
  try
    LoadMap(Series1, tmp);
    LoadMap(Series2, tmp, nil, '', '', false);
  finally
    Chart1.Repaint;
    Chart2.Repaint;
  end;
end;

procedure TForm1.Chart1Click(Sender: TObject);
begin
  TeeCommander1.Panel := Chart1;
end;

procedure TForm1.Chart2Click(Sender: TObject);
begin
  TeeCommander1.Panel := Chart2;
end;
Note that in this simple test project there is only a TeeCommander, two charts and a button added at design time.