MapWinGIS ActiveX Control

repository·develop·Indexed 43 days ago

https://github.com/mapwindow/mapwingis

A free, open-source C++ based ActiveX control and API that provides GIS and mapping capabilities to Windows Forms applications. It supports reading and writing shapefiles, TIN and grid files, and provides projection routines. It can be integrated into applications written in C#, Visual Basic, Delphi, or other languages supporting ActiveX.

Tokens
13.2K
Snippets
27
Records
40
Agent score
55%

What's inside MapWinGIS

  1. Overview of the MapWinGIS ActiveX Control DLL structure

    develop

    MapWinGIS is distributed as an ActiveX Control DLL. The project structure is organized into core DLL management files and the specific Map control implementation.

    Core DLL Files

    • MapWinGIS.h: The primary include file for the ActiveX Control DLL.
    • MapWinGIS.cpp: Handles DLL initialization, termination, and bookkeeping.
    • MapWinGIS.def: Contains essential information required by Microsoft Windows to run the DLL.
    • MapWinGIS.odl: Contains the Object Description Language source code for the control's type library.
    • MapWinGIS.rc: Manages Windows resources used by the project.

    Map Control Implementation

    • Map.h / Map.cpp: Declares and implements the CMapView C++ class, which is the core map control.
    • MapPpg.h / MapPpg.cpp: Declares and implements the CMapViewPropPage C++ class, used for property pages.
    • Map.bmp: The bitmap used to represent the CMapView control on tool palettes.
  2. What is MapWinGIS?

    develop
    MapWinGIS.ocx is a free and open-source C++ based ActiveX Control and Application Programmer Interface (API) designed to provide GIS and mapping functionality to Windows Forms-based applications. It can be integrated into applications written in C#, Visual Basic, Delphi, or any other language that supports ActiveX.
  3. Build the MapWinGIS SpatialIndex static library

    develop

    To build the MapWinGIS version of the SpatialIndex library, use the provided Visual Studio solution file. This version is configured as a static library (.lib) rather than a dynamic library (.dll).

    1. Open spatialindex-mw.sln using Visual Studio (VS2008 or compatible).
    2. Use the Batch Build feature to build both the Win32 and x64 versions.
    Batch Build both Win32 and x64 versions using spatialindex-mw.sln
  4. Manage Spatial Index storage types

    develop

    The Index class allows you to switch between different storage backends using SetIndexStorage and GetIndexStorage.

    • RT_Disk: Stores the index on disk. Requires the FileName property to be set to a valid path.
    • RT_Memory: Stores the index entirely in memory.
    • RT_Custom: Uses a custom storage manager provided via properties.

    If you attempt to use RT_Disk without providing a FileName, the initialization will throw a std::runtime_error.

  5. How quadtree searching works in ShapeLib

    develop

    Searching the ShapeLib quadtree is a multi-stage process designed to balance speed and accuracy. Developers implementing spatial queries should follow this pattern:

    1. Phase 1: Quadtree Traversal: Use SHPTreeFindLikelyShapes() to traverse the quadtree. This collects the shapeids of all shapes contained in quadtree nodes whose bounding rectangles overlap the search rectangle. This phase may return "false positives" because a shape's bounding box is often significantly smaller than its containing tree node.
    2. Phase 2: Shape Verification: Fetch the actual shapes associated with the collected shapeids and verify if their specific bounding boxes fall within the area of interest.
    3. Phase 3: Geometry Verification (Optional): For high precision, verify if the actual line segments or geometry of the shape cross the area of interest. This is more complex and often handled by the drawing engine's clipping logic rather than the search index.
  6. Build and install ShapeLib using CMake

    develop

    You can build ShapeLib on Unix, MinGW, MSYS, or Windows using the provided CMake build system. This system replaces the traditional Makefile and makefile.vc with a more flexible approach that supports full testing.

    Prerequisites

    1. Download eg_data (Optional): Download the example data tree (e.g., via wget http://dl.maptools.org/dl/shapelib/shape_eg_data.zip) to enable 'stream1' tests.
    2. Download ShapeLib Source: Obtain shapelib-1.3.0.tar.gz from OSGeo and unpack it.
    3. Prepare Source Tree:
      • Copy the CMakeLists.txt file from this repository into the top-level of the unpacked ShapeLib source tree.
      • Apply the shapelib.patch to the source tree using patch -p1 < path/to/shapelib.patch. This patch optionally quiets error messages when ShapeLib cannot open shapefiles.

    Build Steps

    Create a separate build directory to perform an out-of-source build.

    1. Configure

    Run cmake with your preferred compiler and options.

    • Use -G "Unix Makefiles" for Linux/Unix.
    • Use -G "MSYS Makefiles" for MinGW/MSYS.
    • Use -DEG_DATA:PATH=<path> to specify the location of the eg_data directory. If this is not provided, 'stream1' tests will be skipped.

    2. Build and Install

    Use make to compile and install the library.

    3. Test

    Run ctest to execute the test suite.

    # 1. Setup source (example assumes source is in ../shapelib-1.3.0)
    mkdir build_dir
    cd build_dir
    
    # 2. Configure
    # Note: -DEG_DATA:PATH is required for 'stream1' tests
    env CC=gcc CFLAGS="-O3 -Wuninitialized" \
    cmake \
    -G "Unix Makefiles" \
    -DCMAKE_INSTALL_PREFIX=/home/software/shapelib/install \
    -DEG_DATA:PATH=/home/software/shapefile/eg_data/ \
    ../shapelib-1.3.0 >& cmake.out
    
    # 3. Build and install
    make VERBOSE=1 -j4 install >& install.out
    
    # 4. Test
    ctest
  7. Build ShapeLib with VC++

    develop

    To build the ShapeLib distribution using Microsoft Visual C++:

    1. Navigate to the shapelib subdirectory after unpacking.
    2. Open a DOS/Command Prompt window.
    3. Run the following command:
    nmake -f makefile.vc

    Alternatively, you can create a Win32 console application project in Visual Studio by including the following files:

    • shpopen.c
    • shptree.c
    • shptreedump.c
  8. Configure Spatial Index properties

    develop

    The Index class uses a Tools::PropertySet to configure the behavior and storage of the spatial index. When initializing or modifying an index, you can set several key properties via the m_properties object.

    Supported Properties

    Property NameTypeDescription
    IndexTypeRTIndexType (ULONG)The type of spatial index (e.g., RT_RTree, RT_MVRTree, RT_TPRTree).
    IndexStorageTypeRTStorageType (ULONG)Where the index is stored (RT_Disk, RT_Memory, or RT_Custom).
    FileNameTools::VT_PCHARThe file path used if IndexStorageType is set to RT_Disk.
    TreeVariantRTIndexVariant (ULONG)The specific variant of the tree (e.g., RStar for R-Trees).
    FillFactordoubleThe fill factor for the index.
    IndexCapacityuint32_t (ULONG)The capacity of the index.
    LeafCapacityuint32_t (ULONG)The capacity of the leaf nodes.
    Dimensionuint32_t (ULONG)The number of dimensions for the spatial index.
    IndexIdentifierint64_t (LONGLONG)A unique identifier for the index.
    ResultSetOffsetint64_t (LONGLONG)The starting offset for result sets.
    ResultSetLimitint64_t (LONGLONG)The maximum number of results to return.