<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hola,<br>
    <br>
    El 19/07/11 10:42, V&iacute;ctor Gonz&aacute;lez escribi&oacute;:
    <blockquote
cite="mid:CAGVwcX4r=Mv2KxdmNLJA3d2V8+SHXyRrrDy-pKtN8ys=i3MAQA@mail.gmail.com"
      type="cite">Hola,<br>
      <br>
      Lo de la constante y lo de la precisi&oacute;n ya est&aacute; solucionado,
      gracias ;-) <br>
      <br>
      En cuanto a pasar la geometr&iacute;a de JTS a fmap, la verdad es que en
      el ejemplo que he puesto es un poco absurdo, pero el caso es que
      el wrapper que estoy intentando hacer en parte consiste en coger
      las geometr&iacute;as de JTS que gasta GGL2 y escribirlas con gvSIG.<br>
    </blockquote>
    <br>
    Entonces puedes usar las operaciones sobre geometr&iacute;as. En este caso,
    la operaci&oacute;n fromJTS. Ej:<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GeometryOperationContext ctx = new
    GeometryOperationContext();<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ctx.setAttribute(FromJTS.PARAM, jtsGeom);<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Geometry gvsigGeom =
    (Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx);<br>
    <br>
    Si fueras a aplicar la misma operaci&oacute;n a muchas geometr&iacute;as tambi&eacute;n
    puedes obtener la operaci&oacute;n mediante el m&eacute;todo
    GeometryManager.getGeometryOperation().<br>
    <br>
    Saludos,<br>
    <pre class="moz-signature" cols="72">-- 
C&egrave;sar Ordi&ntilde;ana Navarro
gvSIG software architect
DiSiD Technologies (<a class="moz-txt-link-freetext" href="http://www.disid.com">http://www.disid.com</a>)</pre>
    <br>
    <blockquote
cite="mid:CAGVwcX4r=Mv2KxdmNLJA3d2V8+SHXyRrrDy-pKtN8ys=i3MAQA@mail.gmail.com"
      type="cite">
      <br>
      Un saludo y gracias otra vez,<br>
      V&iacute;ctor.<br>
      <br>
      <div class="gmail_quote">El 18 de julio de 2011 17:09, Jorge Piera
        Llodr&aacute; <span>&lt;<a moz-do-not-send="true"
            href="mailto:jpiera@gvsig.com">jpiera@gvsig.com</a>&gt;</span>
        escribi&oacute;:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div>
            Hola.
            <div>
              <div class="h5"><br>
                <br>
                <br>
                <br>
                On 07/18/2011 12:42 PM, V&iacute;ctor Gonz&aacute;lez wrote:
                <blockquote>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>
              </div>
            </div>
            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.
            <div class="im"><br>
              <blockquote>
                <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>
            </div>
            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.
            <div class="im"><br>
              <blockquote>
                <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>
            </div>
            Aqu&iacute; no te sabr&iacute;a responder...
            <div class="im"><br>
              <blockquote>
                <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>
            </div>
            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>
              <div class="im">
                <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>
              </div>
              <pre><fieldset></fieldset>
_______________________________________________
gvSIG_desarrolladores mailing list
<a moz-do-not-send="true" href="mailto:gvSIG_desarrolladores@listserv.gva.es">gvSIG_desarrolladores@listserv.gva.es</a>
<a moz-do-not-send="true" 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>-- 
Jorge Piera Llodr&aacute;
gvSIG software architect
PRODEVELOP
e-mail: <a moz-do-not-send="true" href="mailto:jpiera@gvsig.com">jpiera@gvsig.com</a>
<a moz-do-not-send="true" href="http://www.prodevelop.es">http://www.prodevelop.es</a>
<a moz-do-not-send="true" href="http://www.gvsig.org">http://www.gvsig.org</a>
</pre>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>