shapefile creation in memory

Jan 26, 2011 at 7:36 AM

Hi people,

in the old forum, i've read a discussion about the in memory creation of a shapefile; i've read also that this kind of creation is useful to have a fast redrawing of shapes in shapefile.

I've only found vb code, but i'm using vc++ and i haven't found some similar code about.

I'm using 4.8 version of ocx component

Any suggestion?

 

Thanks a lot!

Seum

Jan 26, 2011 at 7:38 AM

Sorry,

i'm using 4.7 version of mapwingis ocx

 

Developer
Feb 3, 2011 at 8:11 PM

Seum,

to create in memory shapefile just call Shapefile.CreateNew() or Shapefile.Open() with the empty name (""). Then you should add shapes from your code.

Actually the speed will be the same as for ordinary disk-based shapefile in editing mode (after Shapefile.StartEditingShapes). And there won't be noticeable speed gain comparing to regular disk-based drawing (Shapefile.EditingShapes = false) for 4.7 version.

To achieve at least some speed while holding shapes in memory you should set Shapefile.CacheExtents property to true. After editing of shapes call Shapefile.RefreshShapeExtents(for a particular shape) and Shapefile.RefreshExtents (for the whole shapefile). 

Currently I'm working on speed optimizations for shapefile drawing. There will be new Shapefile.FastMode property which will work for both regular and editing mode. The preliminary results are quite promising. The redraw time for large shapefiles at full scale in the disk-based mode are 3 times faster (reduced from 1.2 to 0.4 sec for 20 mb shapefile).  So keep watching the updates of the source code ;)

Regards,

Sergei

Feb 4, 2011 at 8:26 AM

"...To achieve at least some speed while holding shapes in memory you should set Shapefile.CacheExtents property to true. After editing of shapes call Shapefile.RefreshShapeExtents(for a particular shape) and Shapefile.RefreshExtents (for the whole shapefile). ..."

So,  can I replace the Redraw() calls with these??

It will be awesome!!And application speed increases i think...

 

Developer
Feb 4, 2011 at 9:04 AM

I guess CacheExtents/RefreshExtents aren't working like this. 

For disk-based shapefiles extents (the bounding rectangle) don't change. They are stored in shapefile explicitly and can be retrieved very fast.

When shapefile in edit mode extents of particular shapes or shapefile as a whole may change as you move, add or delete shapes.

The default behavior of MapWinGIS was to recalculate extents of ALL shapes before EVERY redraw of shapefile, which was very inefficient. 

So the 3 methods was added to trigger extents recalculation only when it's actually needed (some editing took place).

But it's no replacement for Redraw()