How to Use a Shapefile in Weave

Cohga does not recommend using shapefiles in your Weave setup however they can be useful for use in the short term. Our view is always that corporate data should be stored, managed, accessed and edited through an RDBMS however we believe that shapefiles have a place. 

Things to note when using shapefiles:

  1. They are not recommended for broad scale corporate use.
  2. The best performance will be achieved when the shapefiles are on the Weave server.

When using shapefiles, they can be used in Weave's Mapping Engine, Spatial Engine and Data Source. The example on this page covers all these items though they do not all need to be used - pick and chose the parts you need for your setup. 

When using shapefiles, we use a spatial data connection to expose the tables via the Spatial Engine, rather than using a datasource. This will give the same result as a datasource as the Spatial Engine reads the shapefile's DBF file to access the attributes. 


Step-by-step guide

  1. If you want to use the shapefile in the Map View as a layer then:
    1. Add the shapefile to the map service so that it will be rendered, e.g. to the ArcMap document, QGIS project, or GeoServer workspace, then set symbology and publish map service.
    2. Add the layer to the Table of Contents (ToC), as you would for any other layer. 

  2. To use the shapefile as a Spatial Engine:
    1. Create a new Spatial Engine for the shapefile.

      Spatial Engine
      <spatialengine id="spatialengine.shapefile">
      	<dbtype>shapefiledir</dbtype>
      	<url><![CDATA[file:C:\Data\WeaveData\shapefiles]]></url>
      	<memorymapped>true</memorymapped>
      	<createspatialindex>true</createspatialindex>
      </spatialengine>
    2. Add an entity and spatial mapper.

      Entity and Spatial Mapper
      <entity id="drainagepits">
      	<label>Drainage Pits</label>
      </entity>
      <mapper id="mapper.shapefile">
      	<spatialengine>spatialengine.shapefile</spatialengine>
      	<mapping>
      		<entity>drainagepits</entity>
      		<table>am_drainagepits</table>
      		<key>fid</key>
      	</mapping>
      </mapper> 
    3. Attach the entity to the entry in the ToC (otherwise the entity will exist but not be connected to a layer).

      Table of Contents
      <toc:model id='toc.main'>
      	<entry toc='toc.selection'/>
      	<mapengine>mapengine.main</mapengine>
      	...
      	<entry id='l_mapengine.testing_drainage_pits' layer='Drainage Pits (Shapefile)' label='Drainage Pits' checked='false' entity='drainagepits'/>
      	...
      </toc:model>
      
    4. Note, if the projection of the data is not being picked up then you might need to change the Spatial Mapper to explicitly state the projection. 

      <mapper id="mapper.shapefile">
      	<spatialengine>spatialengine.shapefile</spatialengine>
      	<crs>EPSG:4326</crs>
      	<mapping>
      		<entity>drainagepits</entity>
      		<table>am_drainagepits</table>
      		<key>fid</key>
      	</mapping>
      </mapper> 
  3. And finally, to use the shapefile as a Data Source to access its attributes:
    1. Create a new Data Definition for the entity.

      Data Definition
      <datadefinition id="dd_drainagepit">
      	<spatialdataconnection entity="drainagepits">
      	</spatialdataconnection>
      </datadefinition>
      
      <data id="drainagepits" label="Drainage Pits" entity="drainagepits" datadefinition="dd_drainagepit"/>


      To begin with, don't add any <parameter> tags, just let all the attributes appear in the Data Grid. Once the shapefile is working as expected, add a Data Definition as for any other Entity as shown below.

      Data Definition
      <data:datadefinition id='dd_drainagepit'>
      	<spatialdataconnection entity="drainagepits">
      		<parameter name='unitid'   label='Unit Id'   column='unitid'/>                 
      		<parameter name='planno'   label='Plan Number'   column='planno'/>                 
      		<parameter name='sheet'    label='Sheet'    column='sheet'/>                  
      		<parameter name='pitno'    label='Pit Number'    column='pitno'/>                  
      		<parameter name='type'     label='Type'     column='type'/>                   
      		<parameter name='comment1' label='Comment A' column='comment1'/>               
      		<parameter name='comment2' label='Comment B' column='comment2'/>               
      		<parameter name='status'   label='Status'   column='status'/>                 
      	 </spatialdataconnection>
      </data:datadefinition>
      <data:data id="drainagepits" label="Drainage Pits" entity="drainagepits" datadefinition="dd_drainagepit" />


Also refer to the following sections of the Weave System Administrator Guides:

Filter by label

There are no items with the selected labels at this time.