<!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&iacute;ctor Gonz&aacute;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&eacute;todo main:<br>
  <br>
  <span style="font-family: courier new,monospace;">1&nbsp;&nbsp; &nbsp; public static
void main(String[] args) throws Exception {</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">2&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; new
DefaultLibrariesInitializer().fullInitialize();</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">3&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
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&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
EditableFeatureType type = new DefaultEditableFeatureType();</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">6 &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;
type.add("geom", 66).setGeometryType(Geometry.TYPES.POINT)</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">7&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
.setGeometrySubType(Geometry.SUBTYPES.GEOM2D)</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">8&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
.setObjectClass(Geometry.class);</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">9&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
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 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
NewFeatureStoreParameters destParams = (NewFeatureStoreParameters)
manager</span><br style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">12 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
.createNewStoreParameters("FilesystemExplorer", "Shape");</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">13 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
destParams.setDynValue("shpfile", "/tmp/mySHP.shp");</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">14 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf");</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">15 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
destParams.setDynValue("shxfile", "/tmp/mySHP.shx");</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">16 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
destParams.setDynValue("crs", "EPSG:23030");</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">17 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
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 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
manager.newStore("FilesystemExplorer", "Shape", destParams, true);</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">20 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
FeatureStore store = (FeatureStore) manager.openStore("Shape",</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">21 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
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 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
store.edit();</span><br style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">24 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
EditableFeature feature = store.createNewFeature().getEditable();</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">25 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
com.vividsolutions.jts.geom.Geometry g = new GeometryFactory()</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">26 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
.createPoint(new Coordinate(0, 0));</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">27 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Geometry
fmapGeom = Converter.jtsToGeometry(g);</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">28 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
feature.set(feature.getType().getDefaultGeometryAttributeIndex(),</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">29 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
fmapGeom);</span><br style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">30 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
feature.set("double", 57.0);</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">31 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
store.insert(feature);</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">32 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
store.finishEditing();</span><br
 style="font-family: courier new,monospace;">
  <span style="font-family: courier new,monospace;">33 &nbsp;&nbsp; }</span><br>
  <br>
Como veis, trato de escribir un &uacute;nico registro en un shp que tiene dos
campos: la geometr&iacute;a y un real. Mis dudas y problemas son:<br>
  <ul>
    <li>En la l&iacute;nea 6, para indicar que el tipo es geom&eacute;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&aacute; en el proyecto de gemetr&iacute;as, concretamente
la clase se llama org.gvsig.fmap.geom.DataTypes. El DataTypes de tools
tiene los tipos b&aacute;sicos y hay algunas librer&iacute;as que aportan nuevos
tipos de datos. En concreto, la librer&iacute;a de geometr&iacute;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&iacute;nea 27, Converter est&aacute; marcado como @deprecated, pero
no he encontrado ninguna alternativa para convertir una geometr&iacute;a de
JTS a fmap.</li>
  </ul>
</blockquote>
Bueno, la idea es que no tengas que crear una geometr&iacute;a de JTS y que
puedas crear directamente la geometr&iacute;a de gvSIG. Crear un punto en 2
dimensiones con las coordenadas 0,0 se har&iacute;a as&iacute;:<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&ntilde;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&iacute; no te sabr&iacute;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&oacute;digo el resultado es el mismo. He probado a cambiar el
valor del double a 34.0 as&iacute; arbitrariamente y entonces se escribe un 3.0</li>
  </ul>
</blockquote>
Parece ser que tienes un problema de precisi&oacute;n. El m&eacute;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&oacute;n que he mirado es la de la web [1][2]. Para las dos
&uacute;ltimas, no tengo muy claro si es que no he utilizado la api
correctamente, o es un bug o qu&eacute;.<br>
  <br>
Gracias de antemano,<br>
V&iacute;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&aacute;
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>