MapWindow Developer Team : MapWindow Discussion Forum
I'm working on a new plugin and I see a new option on the shapefileClass: CreateSpatialIndex. But I have no idea how to use it and if I want to use it. I found the post by Andrew Purkis saying he has added it, but no explanation. The wiki has nothing nor d
How to use sf.CreateSpatialIndex()?
Posted by: pmeems ()
Date: February 20, 2009 02:10PM

I'm working on a new plugin and I see a new option on the shapefileClass:
CreateSpatialIndex.

But I have no idea how to use it and if I want to use it.
I found the post by Andrew Purkis saying he has added it, but no explanation.
The wiki has nothing nor does Intellisense has.

The biggest confusion it that the parameter needed is a shapefilename. But because it is part of the shapefile it already has the shapefilename or does it need another on?
This is how I thought I'd use it:
MapWinGIS.ShapefileClass sf = new MapWinGIS.ShapefileClass();
if (!sf.CreateNewWithShapeID(filename, MapWinGIS.ShpfileType.SHP_POLYGON))
{
    throw new Exception("Error in CreateNewWithShapeID: "
     + sf.get_ErrorMsg(sf.LastErrorCode);
}
sf.CreateSpatialIndex(sf.Filename);
// Add some polygons:

Has anyone used it before?

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Re: How to use sf.CreateSpatialIndex()?
Posted by: apurkis ()
Date: February 23, 2009 07:04AM

Paul,

My apologies for the confusion. When I was developing and testing the functionality I was not using MapWinGIS, so I needed to pass in the full path to the shapefile. I never got around to using the built in file name. So you need to pass in the full path to the shapefile.

This function has been designed for use on existing shapefiles, and won't work when creating shapefiles on-the-fly. The spatial indexing really makes a difference when you have very large shapefiles, and are only selecting a portion of the shapefile extent. We use it on city lot polygons which can have up to 250,000 polygons. If we displayed all 250,000 polygons it would take exactly the same amount of time with or without a spatial index, realistically though we only display 500-800 at a time, so the gains in rendering time are significant.

That being said, functionality does exist within the spatial indexing dll to add and delete items to the index, but because of lack of time, I have not built those interfaces into the ocx. I will add that functionality at a later date, when I get some free time.

Hope that helps,

Andrew Purkis

Re: How to use sf.CreateSpatialIndex()?
Posted by: pmeems ()
Date: February 25, 2009 04:32AM

Thanks Andrew for the explanation.

I'm creating a shapefile with 19,000 polygons so it would be nice to be able to add a spatial index to it.

Please keep me informed with your progress.
Lack of time is also my biggest problem ;)

Thanks,

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Re: How to use sf.CreateSpatialIndex()?
Posted by: Sergei ()
Date: June 12, 2009 04:46PM

Hello, special question for Andrew.

The names of my shapefiles have cyrillic letters and I have problems with spatial indexing.

HasSpatialIndex property returns:
- true for a file named in latin (characters 0-127 of codepage);
- false for the same file if I change filename (shp, shx, dbf, mwd, mwx) to cyrillic (characters 128-255 of codepage).

CreateSpatialIndex function:
- creates index all right for latin letters (0-127);
- crashes IDE for cyrillic letters (128-255) - mwd, mwx files are created but the characters of their names are from different codepage.

Shapefiles:
- are drawn as normal for latin letters;
- are drawn only in edit mode for cyrillic letters (in regular mode shapefiles are not drawn).

I looked through ocx source code for 4.6 and 4.7RC version. The changes in Map.DrawShapefile procedure between versions I found are dealing with SpatialIndexing. So I decided to put this question here (sorry if I'm mistaken).

I haven't got any knowledge of cpp. By msdn, googling and pure guess: in all procedures (CreateSpatialIndex, HasSpatialIndex, additional lines of Map.DrawShapefile) variables of type String are used. I havent's found this type anywhere else in these modules (only CString). Maybe it's a problem with signed/unsigned chars as cyrillic characters are from extended part of codepage (128-255)?
I can't test this myself as to sort out 81 errors while trying to build ocx may take weeks for me.

So maybe Andrew or somebody else with cpp knowledge will help me.

Thanks.

Re: How to use sf.CreateSpatialIndex()?
Posted by: pmeems ()
Date: June 14, 2009 02:33PM

I have no idea about the Cyrillic letters.
Did you already submit a bug report and added some sample data?

I might be able to help you with compiling MapWinGIS.
I do it every Friday for the weekly build using VS2008 Pro.
Rob just has added the VS2003 solution and project file.

Which version of VS are you using and are you using the latest SVN version of the source code?
What are the errors are you getting?

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Re: How to use sf.CreateSpatialIndex()?
Posted by: Sergei ()
Date: June 14, 2009 04:49PM

Hi, Paul.

I added bug report [bugs.mapwindow.org], but there was no answer for some time, so I decided to explore the problem myself.
I wasn't able to upload file named in cyrillic (see error message in bug report). Besides all cyrillic letters turn to ????? when message saved in Mantis. I'll try here: названиефайла.

I'm interested in working with source code for ocx myself (not for this issue only). Some instructions will be helpful for a start.
I have Visual Studio 2008. I downloaded all files from [svn.mapwindow.org] on 12.06.09.

The errors when I tried to build project are:
error C2418: cannot delete browser file: NDebug with Symbols\dbf.sbr c:\dev\activex\dbf\dbf.cpp - 21 errors for different modules
error C2471: cannot update program database 'c:\dev\activex\release\vc90.pdb' c:\dev\activex\dbf\dbf.cpp - 31 errors for different modules
error BK1506 : cannot open file '.\NDebug with Symbols\ESRIGridManager.sbr': No such file or directory BSCMAKE
fatal error C1083: Cannot open include file: 'cpl_string.h': No such file or directory c:\dev\activex\shapefile.cpp
fatal error C1083: Cannot open include file: 'gdal_priv.h': No such file or directory c:\dev\activex\image\tkraster.h - 6 errors
fatal error C1083: Cannot open include file: 'ogr_spatialref.h': No such file or directory c:\dev\activex\projections.h - 2 errors
fatal error C1083: Cannot open include file: 'xtiffio.h': No such file or directory c:\dev\activex\grid\gridmanager.cpp

Thanks for your work.

Re: How to use sf.CreateSpatialIndex()?
Posted by: Rob Cairns ()
Date: June 15, 2009 12:38PM

Hi Sergei

I think that you could try one of the other configurations in vs2008, then copy and paste the paths to the include files and libraries.

With regard to your shapefile names, am I correct in saying you require unicode support for Cryllic letters?

If so - we have a strange situation where mapwingis has unicode support for .shp file names (shapes are handled internally by the ocx) but not for .dbf names (handled by gdal/shapelib). So we have file = _wfopen(T2W(filename), L"rb") for tableclass.cpp and DBFOpen(pszFilename, pszAccess) where pszFilename is const char * at dbf.cpp.

It would be great if you could check at [lists.osgeo.org] and ask how their support for unicode is getting on (see [lists.osgeo.org]) and also how to implement it.

Regards Rob

Re: How to use sf.CreateSpatialIndex()?
Posted by: Sergei ()
Date: June 15, 2009 03:08PM

Hi Rob

No unicode support is needed for the cyrillic letters. The 8-bit encoding win-1251 is used. First part of codepage - standart ASCII. Cyrillic characters have codes from 128 to 255. Here is a link: [en.wikipedia.org]

So my problem is easier I believe. Most likely wrong type for strings or function for their convertion in 4.7RC version. In MapWinGis 4.6 all works right.

Re: How to use sf.CreateSpatialIndex()?
Posted by: Sergei ()
Date: June 15, 2009 03:08PM

...technical problems...



Edited 1 time(s). Last edit at 06/15/2009 03:09PM by Sergei.

Re: How to use sf.CreateSpatialIndex()?
Posted by: apurkis ()
Date: June 16, 2009 12:28PM

Hi Sergei,

Sorry for the delay in replying.

Internally, in the core part of the spatial indexing package the file names are regular char*, so in wrapping it originally, I kept the same format, (Sorry I'm human - path of least resistance!)

I will try to modify it all asap, but I can't make any promises when. If changed it should be changed to be unicode compliant.

Regards Andrew

Re: How to use sf.CreateSpatialIndex()?
Posted by: pmeems ()
Date: June 17, 2009 12:49PM

Sergei,

To compile MapWinGIS you also need the SupportLibraries. Look in SVN for them.
You also need the Pro edition of VS2008 or else you'll be missing some MFC libraries.

Hope it helps.

Paul

--
Don't forget to read the new documentation: www.mapwindow.org/documentation/mapwingis4.8
Join us Google+: MapWindow GIS Google+ Community
Join the MapWindow Group on LinkedIn! LinkedIn - MapWindow Group

Download the latest beta installer at:
tinyurl.com/mwMonthly 32-Bit
tinyurl.com/mwMonthlyx64 64-Bit
Follow me on Twitter MapWindow_nl to read when a new installer is published.

---
Paul Meems
The Netherlands
[www.bontepaarden.nl]
Release manager, configuration manager and
forum moderator of MapWindow GIS

Owner of MapWindow.nl - Support for
Dutch speaking users: www.mapwindow.nl

*******
Everything I say or write is my personal opinion and
not the opinion of the company I work for.
*******
View my profile on LinkedIn

Re: How to use sf.CreateSpatialIndex()?
Posted by: Sergei ()
Date: June 17, 2009 03:51PM

Hi Andrew, glad to hear you. It would be a great thing for me to get rid of this problem.

Thanks, Paul, I'll try it soon. For now I read about cpp a bit as it would be little use to deal with source code without any knowledge.

Regards Sergei

Re: How to use sf.CreateSpatialIndex()?
Posted by: Sergei ()
Date: June 22, 2009 08:38AM

Andrew,

I've compiled ocx and found solution for the problem with redrawing of shapefiles. As it is not connected with spatial indexing I started a new topic [www.mapwindow.org].

About spatial indexing and cyrillic names:
- creating index: there is no crash now, though names of mwd, mwx files are still incorrect and the files are empty.
- filenames are correct when they are passed to IndexSearching.dll (in get_HasSpatialIndex function for example). So the problem most likely is in the dll itself.

Sorry, only registered users may post in this forum.





Banner Exchange




GISCP.com




Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

Just paste this text in your page: