[mapserver-users] RE OGR csv - no field names

Simon Mercier smercier at mapgears.com
Tue Apr 26 08:00:46 PDT 2016


Ian

Try with FID field, OGR generate this ID for you. But you should try use 
your own ID field for consistency between version of your data (if 
needed). I tested with my demo data and I can select FID even if it 
doesn't exist in source file.

<OGRVRTDataSource>
     <OGRVRTLayer name="Inventory">
<SrcDataSource>/home/smercier/data/vrt/Inventory.csv</SrcDataSource>
         <GeometryType>wkbPoint</GeometryType>
         <LayerSRS>EPSG:4326</LayerSRS>
         <GeometryField encoding="PointFromColumns" x="longitude" 
y="latitude"/>
         <Field name="site_name" src="SiteName"/>
         <Field name="site_phone" src="SitePhone"/>
         <Field name="site_type" src="SiteType"/>
         <Field name="address" src="address"/>
         <Field name="site_aed_placement" src="AEDPlacementLocation"/>
     </OGRVRTLayer>
</OGRVRTDataSource>

smercier at optimus: $ ogrinfo Inventory.vrt -sql "select fid from Inventory"
INFO: Open of `Inventory.vrt'
       using driver `VRT' successful.

Layer name: Inventory
Geometry: Point
Feature Count: 117
Extent: (-80.977043, 0.000000) - (0.000000, 43.978620)
Layer SRS WKT:
GEOGCS["WGS 84",
     DATUM["WGS_1984",
         SPHEROID["WGS 84",6378137,298.257223563,
             AUTHORITY["EPSG","7030"]],
         AUTHORITY["EPSG","6326"]],
     PRIMEM["Greenwich",0,
         AUTHORITY["EPSG","8901"]],
     UNIT["degree",0.0174532925199433,
         AUTHORITY["EPSG","9122"]],
     AUTHORITY["EPSG","4326"]]
fid: Integer (0.0)
OGRFeature(Inventory):1
   fid (Integer) = 1
   POINT (-80.2171407 43.4970847)

OGRFeature(Inventory):2
   fid (Integer) = 2
   POINT (-80.5357573 43.8367679)

OGRFeature(Inventory):3
   fid (Integer) = 3
   POINT (0 0)
....


On 16-04-25 07:11 PM, Ian Walberg wrote:
> Jeff,
>
> Many thanks that worked great.
>
> Next is there any way of getting the row ID as part of the data passed to mapserver?
>
> We are planning to serve this data as a WFS layer.
>
> Thanks
>
> Ian
>
> -----Original Message-----
> From: mapserver-users [mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Jeff McKenna
> Sent: Monday, April 25, 2016 3:03 PM
> To: mapserver-users at lists.osgeo.org
> Subject: Re: [mapserver-users] RE OGR csv - no field names
>
> On 2016-04-25 6:49 PM, Simon Mercier wrote:
>> really not sure CSVT file is supported by ogr, but you can easily
>> define field type in VRT
>>
>>           <Field name="precipitation_mm" src="prec_mm" type="Real"/>
>>           <Field name="field_1" src="field_1" type="String" width="100"
>> />
>>
> Simon is right, very nice, specifying the field name to classify in the vrt works, for a csv without field names:
>
> <OGRVRTDataSource>
>       <OGRVRTLayer name="occurrence">
>           <SrcDataSource relativeToVRT="1">CSV:occurrence.txt</SrcDataSource>
>           <GeometryType>wkbPoint</GeometryType>
>           <LayerSRS>WGS84</LayerSRS>
>           <GeometryField encoding="PointFromColumns" x="field_37"
> y="field_38"/>
>           <Field name="name" src="field_51" type="String" width="100"/>
>       </OGRVRTLayer>
> </OGRVRTDataSource>
>
>
>
> LAYER
>     NAME "occurrence"
>     TYPE POINT
>     STATUS ON
>     CONNECTIONTYPE OGR
>     CONNECTION "../occurrence.vrt"
>     CLASSITEM "name"
>     CLASS
>       NAME "Occurrences"
>       EXPRESSION "ttt"
>       STYLE
>         SYMBOL 7
>         SIZE 10
>         COLOR 0 0 0
>       END
>     END
> END # Layer
>
>
> -jeff
>
>
>
>
>
> --
> Jeff McKenna
> MapServer Consulting and Training Services http://www.gatewaygeomatics.com/
>
>
>
>
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users

-- 
simon mercier
mapgears
+1.418.476.7139 p101



More information about the mapserver-users mailing list