<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Hola.<br>
<br>
<br>
<br>
On 07/18/2011 12:42 PM, Víctor González wrote:
<blockquote
cite="mid:CAGVwcX4DyXVWnPnhLsB45jVnTxwtP7uCG8boDXNydG-=aFJwRA@mail.gmail.com"
type="cite">Hola,<br>
<br>
Estoy intentando escribir shapefiles con gvSIG y me han salido
bastantes dudas y problemas que he intentado aislar en el siguiente
método main:<br>
<br>
<span style="font-family: courier new,monospace;">1 public static
void main(String[] args) throws Exception {</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">2 new
DefaultLibrariesInitializer().fullInitialize();</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">3
DataManager manager = DALLocator.getDataManager();</span><br
style="font-family: courier new,monospace;">
4 <br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">5
EditableFeatureType type = new DefaultEditableFeatureType();</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">6
type.add("geom", 66).setGeometryType(Geometry.TYPES.POINT)</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">7
.setGeometrySubType(Geometry.SUBTYPES.GEOM2D)</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">8
.setObjectClass(Geometry.class);</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">9
type.add("double", DataTypes.DOUBLE);</span><br
style="font-family: courier new,monospace;">
10<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">11
NewFeatureStoreParameters destParams = (NewFeatureStoreParameters)
manager</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">12
.createNewStoreParameters("FilesystemExplorer", "Shape");</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">13
destParams.setDynValue("shpfile", "/tmp/mySHP.shp");</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">14
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf");</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">15
destParams.setDynValue("shxfile", "/tmp/mySHP.shx");</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">16
destParams.setDynValue("crs", "EPSG:23030");</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">17
destParams.setDefaultFeatureType(type);</span><br
style="font-family: courier new,monospace;">
18<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">19
manager.newStore("FilesystemExplorer", "Shape", destParams, true);</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">20
FeatureStore store = (FeatureStore) manager.openStore("Shape",</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">21
destParams);</span><br style="font-family: courier new,monospace;">
22<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">23
store.edit();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">24
EditableFeature feature = store.createNewFeature().getEditable();</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">25
com.vividsolutions.jts.geom.Geometry g = new GeometryFactory()</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">26
.createPoint(new Coordinate(0, 0));</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">27 Geometry
fmapGeom = Converter.jtsToGeometry(g);</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">28
feature.set(feature.getType().getDefaultGeometryAttributeIndex(),</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">29
fmapGeom);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">30
feature.set("double", 57.0);</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">31
store.insert(feature);</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">32
store.finishEditing();</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">33 }</span><br>
<br>
Como veis, trato de escribir un único registro en un shp que tiene dos
campos: la geometría y un real. Mis dudas y problemas son:<br>
<ul>
<li>En la línea 6, para indicar que el tipo es geométrico pongo un
66, que es lo que he observado que me ha devuelto en otros casos al
leer, pero no he encontrado en DataTypes (ni en otro sitio) una
constante para identificar esto.</li>
</ul>
</blockquote>
La constante que buscas está en el proyecto de gemetrías, concretamente
la clase se llama org.gvsig.fmap.geom.DataTypes. El DataTypes de tools
tiene los tipos básicos y hay algunas librerías que aportan nuevos
tipos de datos. En concreto, la librería de geometrías tiene un
DataTypes que define el tipo GEOMETRY y ENVELOPE.<br>
<blockquote
cite="mid:CAGVwcX4DyXVWnPnhLsB45jVnTxwtP7uCG8boDXNydG-=aFJwRA@mail.gmail.com"
type="cite">
<ul>
<li>En la línea 27, Converter está marcado como @deprecated, pero
no he encontrado ninguna alternativa para convertir una geometría de
JTS a fmap.</li>
</ul>
</blockquote>
Bueno, la idea es que no tengas que crear una geometría de JTS y que
puedas crear directamente la geometría de gvSIG. Crear un punto en 2
dimensiones con las coordenadas 0,0 se haría así:<br>
<br>
GeometryManager geometryManager = GeometryLocator.getGeometryManager();<br>
Point point = geometryManager.createPoint(0, 0,
Geometry.SUBTYPES.GEOM2D);<br>
<br>
Y ese punto ya lo puedes añadir a la feature de gvSIG sin tener que
convertir nada a JTS.<br>
<blockquote
cite="mid:CAGVwcX4DyXVWnPnhLsB45jVnTxwtP7uCG8boDXNydG-=aFJwRA@mail.gmail.com"
type="cite">
<ul>
<li>Cuando intento abrir el shp que he escrito con geotools, me
dice que "ShapeType changed illegally from PointZ to Point".</li>
</ul>
</blockquote>
Aquí no te sabría responder...<br>
<blockquote
cite="mid:CAGVwcX4DyXVWnPnhLsB45jVnTxwtP7uCG8boDXNydG-=aFJwRA@mail.gmail.com"
type="cite">
<ul>
<li>Con gvSIG Desktop puedo abrir el shapefile, pero cuando lo
muestro en una tabla, me aparece que el valor de "double" es 5.0. Si lo
leo mediante código el resultado es el mismo. He probado a cambiar el
valor del double a 34.0 así arbitrariamente y entonces se escribe un 3.0</li>
</ul>
</blockquote>
Parece ser que tienes un problema de precisión. El método add del
EditableFeatureType devuelve un EditableFeatureAttributeDescriptor que
tiene un setSize. Es como si la longitud por defecto fuese de 1.<br>
<br>
Un saludo,<br>
Jorge<br>
<blockquote
cite="mid:CAGVwcX4DyXVWnPnhLsB45jVnTxwtP7uCG8boDXNydG-=aFJwRA@mail.gmail.com"
type="cite">
<ul>
</ul>
Pues eso es todo. Con respecto a las dos primeras cuestiones, la
documentación que he mirado es la de la web [1][2]. Para las dos
últimas, no tengo muy claro si es que no he utilizado la api
correctamente, o es un bug o qué.<br>
<br>
Gracias de antemano,<br>
Víctor.<br>
<br>
[1] <a moz-do-not-send="true"
href="http://www.gvsig.org/web/projects/gvsig-desktop/docs/devel/org.gvsig.fmap.dal">http://www.gvsig.org/web/projects/gvsig-desktop/docs/devel/org.gvsig.fmap.dal</a><br>
[2] <a moz-do-not-send="true"
href="http://www.gvsig.org/web/projects/gvsig-desktop/docs/devel/org.gvsig.fmap.geom">http://www.gvsig.org/web/projects/gvsig-desktop/docs/devel/org.gvsig.fmap.geom</a><br>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
gvSIG_desarrolladores mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gvSIG_desarrolladores@listserv.gva.es">gvSIG_desarrolladores@listserv.gva.es</a>
<a class="moz-txt-link-freetext" href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Jorge Piera Llodrá
gvSIG software architect
PRODEVELOP
e-mail: <a class="moz-txt-link-abbreviated" href="mailto:jpiera@gvsig.com">jpiera@gvsig.com</a>
<a class="moz-txt-link-freetext" href="http://www.prodevelop.es">http://www.prodevelop.es</a>
<a class="moz-txt-link-freetext" href="http://www.gvsig.org">http://www.gvsig.org</a>
</pre>
</body>
</html>