Пример #1
0
  public static void reportExceptions(
      ArrayList exceptions, DataSourceQuery dataSourceQuery, WorkbenchContext context) {
    context
        .getIWorkbench()
        .getFrame()
        .getOutputFrame()
        .addHeader(
            1,
            exceptions.size()
                + " problem"
                + StringUtil.s(exceptions.size())
                + " loading "
                + dataSourceQuery.toString()
                + "."
                + ((exceptions.size() > 10) ? " First and last five:" : ""));
    context.getIWorkbench().getFrame().getOutputFrame().addText("See View / Log for stack traces");
    context.getIWorkbench().getFrame().getOutputFrame().append("<ul>");

    Collection exceptionsToReport =
        exceptions.size() <= 10
            ? exceptions
            : CollectionUtil.concatenate(
                Arrays.asList(
                    new Collection[] {
                      exceptions.subList(0, 5),
                      exceptions.subList(exceptions.size() - 5, exceptions.size())
                    }));
    for (Iterator j = exceptionsToReport.iterator(); j.hasNext(); ) {
      Exception exception = (Exception) j.next();
      context.getIWorkbench().getGuiComponent().log(StringUtil.stackTrace(exception));
      context.getIWorkbench().getFrame().getOutputFrame().append("<li>");
      context
          .getIWorkbench()
          .getFrame()
          .getOutputFrame()
          .append(GUIUtil.escapeHTML(WorkbenchFrameImpl.toMessage(exception), true, true));
      context.getIWorkbench().getFrame().getOutputFrame().append("</li>");
    }
    context.getIWorkbench().getFrame().getOutputFrame().append("</ul>");
  }
Пример #2
0
  public static Geometry obtenerGeometriaParcela(String dxf, WorkbenchContext context) {

    Geometry geometryParcela = null;

    GeopistaLoadDxfQueryChooser dxfLoad =
        new GeopistaLoadDxfQueryChooser(Dxf.class, "GEOPISTA dxf", extensions(Dxf.class), context);

    InputStream fileDXF = ImportarUtils_LCGIII.parseStringToIS(dxf);

    try {
      Assert.isTrue(!dxfLoad.getDataSourceQueries(fileDXF).isEmpty());
    } catch (AssertionFailedException e) {
      throw new AssertionFailedException(I18N.get("FileEmpty"));
    }

    fileDXF = ImportarUtils_LCGIII.parseStringToIS(dxf);

    boolean exceptionsEncountered = false;
    for (Iterator i = dxfLoad.getDataSourceQueries(fileDXF).iterator(); i.hasNext(); ) {
      DataSourceQuery dataSourceQuery = (DataSourceQuery) i.next();

      ArrayList exceptions = new ArrayList();
      Assert.isTrue(dataSourceQuery.getDataSource().isReadable());

      Connection connection = dataSourceQuery.getDataSource().getConnection();
      try {
        FeatureCollection dataset =
            dataSourceQuery
                .getDataSource()
                .installCoordinateSystem(
                    connection.executeQuery(dataSourceQuery.getQuery(), exceptions, null), null);
        if (dataset != null) {

          String layerName = dataSourceQuery.toString();
          Geometry geometriaInicial = null;
          GeopistaFeature featureInicial = null;

          if (layerName.startsWith("PG-LP")) {
            // Obtener el borde con las features de la capa
            ArrayList lstFeatures = new ArrayList();
            for (Iterator features = dataset.getFeatures().iterator(); features.hasNext(); ) {
              GeopistaFeature feature = (GeopistaFeature) features.next();
              lstFeatures.add(feature);
            }
            ArrayList coordenadas = new ArrayList();

            if (lstFeatures != null && lstFeatures.size() > 0) {

              featureInicial = (GeopistaFeature) lstFeatures.iterator().next();
              lstFeatures.remove(featureInicial);
              geometriaInicial = featureInicial.getGeometry();
              for (int indice = 0; indice < geometriaInicial.getCoordinates().length; indice++)
                coordenadas.add(geometriaInicial.getCoordinates()[indice]);

              if (geometriaInicial instanceof LineString) {

                Point puntoFinal = ((LineString) geometriaInicial).getEndPoint();
                GeopistaFeature feature = null;
                Geometry geometria = null;
                int indice;

                while (lstFeatures.size() > 0) {
                  boolean encontrado = false;
                  Iterator features = lstFeatures.iterator();
                  while (features.hasNext() && !encontrado) {

                    feature = (GeopistaFeature) features.next();
                    geometria = feature.getGeometry();
                    if (geometria instanceof LineString) {

                      if (puntoFinal.distance(((LineString) geometria).getStartPoint()) == 0) {

                        for (indice = 1; indice < geometria.getCoordinates().length; indice++)
                          coordenadas.add(geometria.getCoordinates()[indice]);
                        puntoFinal = ((LineString) geometria).getEndPoint();
                        encontrado = true;

                      } else if (puntoFinal.distance(((LineString) geometria).getEndPoint()) == 0) {
                        for (indice = geometria.getCoordinates().length - 2; indice >= 0; indice--)
                          coordenadas.add(geometria.getCoordinates()[indice]);

                        puntoFinal = ((LineString) geometria).getStartPoint();
                        encontrado = true;
                      }
                    }
                  }
                  if (encontrado) {
                    lstFeatures.remove(feature);
                  }
                }
                Coordinate[] coordenadasParcela = new Coordinate[coordenadas.size()];
                indice = 0;
                for (Iterator coordenada = coordenadas.iterator(); coordenada.hasNext(); ) {
                  coordenadasParcela[indice] = (Coordinate) coordenada.next();
                  indice++;
                }

                if (coordenadasParcela[0].equals3D(
                    coordenadasParcela[coordenadasParcela.length - 1])) {
                  LinearRing lineaParcela =
                      geometriaInicial.getFactory().createLinearRing(coordenadasParcela);
                  Polygon poligonoParcela = null;
                  poligonoParcela = geometriaInicial.getFactory().createPolygon(lineaParcela, null);
                  geometryParcela = poligonoParcela;
                }
              }
            }
          }
        }
      } finally {
        connection.close();
      }
      if (!exceptions.isEmpty()) {
        if (!exceptionsEncountered) {
          context.getIWorkbench().getFrame().getOutputFrame().createNewDocument();
          exceptionsEncountered = true;
        }
        reportExceptions(exceptions, dataSourceQuery, context);
      }
    }
    if (exceptionsEncountered) {
      context
          .getIWorkbench()
          .getGuiComponent()
          .warnUser("Problems were encountered. See Output Window for details.");
    }

    return geometryParcela;
  }