[Qgis-user] Create polygons with attributes from csv-file

Fernando M. Roxo da Motta petro at roxo.org
Thu May 21 07:23:35 PDT 2015


On Thu, 21 May 2015 15:08:28 +0200, Nicole Stoffels <stoffels at f2e.de>
wrote:

  Hi all,


  I don't know what platform you use, I use Linux and I got an script
from somewhere (sorry, long time ago and I can't recall :( ) to produce
shapefiles from the content of a CVS.   Depending on how skilled you
are in editing in your preferred editor (please guys, no VIM vs Notepad
flamewar) it can be easy to convert this CVS to the script.  I guess
that even a .bat could do, although I don't know the syntax.

  The script bellow will produce the files .dbf, .shx, and .shp.  You
will need to provide a .prj some way.  Of course if you load this
shapefile in Qgis it will ask for the CRS.  The shapefile will have two
polygons and the DBF will have the ID and the height.

#=====================8<------------ cut here ---------------- 

#!/bin/sh
# nome       : makeshape_poly.sh
# autor      : <I really don't remenber where I got this>
# description: 
#   Given sets of points, use them to build a shapefile
#   You will have to provide a $SHPNAM.proj later.
# changelog  : 
# 21/05/2015 - first version

# 
SHPNAM=forests

shpcreate $SHPNAM polygon
dbfcreate $SHPNAM.dbf -n FID        5  0 \
                      -s forestid   8    \
                      -n height     5  2 \


shpadd $SHPNAM.shp 10.915763 54.137004      \
                   10.917392 54.138734      \
                   10.915822 54.140197      \
                   10.913504 54.140824      \
                   10.913541 54.138637

dbfadd $SHPNAM.dbf 1 "forest1" 25


shpadd $SHPNAM.shp 10.897562 54.150324      \
                   10.897907 54.149662      \
                   10.900432 54.148912      \
                   10.901194 54.149092

dbfadd $SHPNAM.dbf 2 "forest2"  20


shpdump $SHPNAM.shp
dbfdump $SHPNAM.dbf

#=====================8<------------ cut here ----------------


  Hope this helps.



> Dear QGIS-users,
> 
> I have a csv-file containing the corner coordinates of different
> forests with different heights. The file is structured like this:
> 
> FID,forest_id,point_id,X,Y,height
> 1,forest1,point1,10.915763,54.137004,25
> 2,forest1,point2,10.917392,54.138734,25
> 3,forest1,point3,10.915822,54.140197,25
> 4,forest1,point4,10.913504,54.140824,25
> 5,forest1,point5,10.913541,54.138637,25
> 6,forest2,point1,10.897562,54.150324,20
> 7,forest2,point2,10.897907,54.149662,20
> 8,forest2,point3,10.900432,54.148912,20
> 9,forest2,point4,10.901194,54.149092,20
> 
> Now I want to make two polygons from the two different forests
> containing the attribute height. If I had only one forest I would
> create a voronoi diagram and a delaunay triangulation and clipper
> them. But it would be too time consuming to do that for every forest,
> as I usually have rather 10 forests or more. Is there a way to get
> this done if all forests are in one csv-dataset only separated by
> there forest_id?
> 
> Thank you and sorry for the first mail, which was not yet finished.
> 
> Best wishes
> Nicole
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
> 








  Roxo

-- 
---------------- Non luctari, ludare -------------------+ WYSIWYG
Fernando M. Roxo da Motta <petro at roxo.org>              | Editor?
Except where explicitly stated I speak on my own behalf.|  VI !!
      ( Usuário Linux registrado #39505 )               | I see text,
------------ Quis custodiet ipsos custodes?-------------+ I get text!
 



More information about the Qgis-user mailing list