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>");
  }
  public boolean execute(PlugInContext context) throws Exception {
    // Don't make this plug-in undoable -- it's a lot of data to store in memory [Jon Aquino]
    context.getLayerManager().getUndoableEditReceiver().reportIrreversibleChange();

    CoordinateSystem destination =
        (CoordinateSystem)
            JOptionPane.showInputDialog(
                (Component) context.getWorkbenchGuiComponent(),
                AppContext.getApplicationContext().getI18nString("SelectCoordinateReferenceSystem"),
                AppContext.getApplicationContext().getI18nString("CoordinateReferenceSystem"),
                JOptionPane.PLAIN_MESSAGE,
                null,
                new ArrayList(
                        CoordinateSystemRegistry.instance(
                                context.getWorkbenchContext().getBlackboard())
                            .getCoordinateSystems())
                    .toArray(),
                context.getLayerManager().getCoordinateSystem());

    if (destination == null) {
      return false;
    }

    if (context.getLayerManager().getCoordinateSystem() == destination) {
      return true;
    }

    if (Reprojector.instance()
        .wouldChangeValues(context.getLayerManager().getCoordinateSystem(), destination)) {
      // Two-phase commit [Jon Aquino]
      ArrayList transactions = new ArrayList();

      for (Iterator i = context.getLayerManager().iterator(); i.hasNext(); ) {
        Layer layer = (Layer) i.next();
        EditTransaction transaction =
            new EditTransaction(
                layer.getFeatureCollectionWrapper().getFeatures(),
                getName(),
                layer,
                isRollingBackInvalidEdits(context),
                false,
                context.getLayerViewPanel());

        for (int j = 0; j < transaction.size(); j++) {
          Reprojector.instance()
              .reproject(
                  transaction.getGeometry(j),
                  context.getLayerManager().getCoordinateSystem(),
                  destination);
        }

        transactions.add(transaction);
      }

      EditTransaction.commit(transactions);
    }
    // cambia

    for (Iterator i = context.getLayerManager().iterator(); i.hasNext(); ) {
      Layer layer = (Layer) i.next();
      layer.getFeatureCollectionWrapper().getFeatureSchema().setCoordinateSystem(destination);
      DataSourceQuery dsq = layer.getDataSourceQuery();
      if (dsq != null)
        dsq.getDataSource()
            .getProperties()
            .put(DataSource.COORDINATE_SYSTEM_KEY, destination.getName());
    }

    context.getLayerManager().setCoordinateSystem(destination);

    if (context.getLayerViewPanel() != null) {
      context.getLayerViewPanel().getViewport().zoomToFullExtent();
    }

    return true;
  }
  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;
  }