Examples of MathTransform


Examples of org.opengis.referencing.operation.MathTransform

    }

    private void dumpMap( GridCoverage2D coverage2D, CoordinateReferenceSystem fileCrs, CoordinateReferenceSystem newCrs,
            String newFilePath, boolean isAscii, boolean isTiff ) throws FactoryException, IOException {
        if (newCrs != null) {
            MathTransform mathTransform = CRS.findMathTransform(fileCrs, newCrs);
            if (!mathTransform.isIdentity()) {
                coverage2D = (GridCoverage2D) Operations.DEFAULT.resample(coverage2D, newCrs);
            }
        }

        if (isTiff) {
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

                ReferencedEnvelope bounds = viewportModel.getBounds();

                CoordinateReferenceSystem mapCrs = viewportModel.getCRS();
                CoordinateReferenceSystem imageCrs = DefaultGeographicCRS.WGS84;
                try {
                    MathTransform transform = CRS.findMathTransform(mapCrs, imageCrs);
                    Envelope targetEnv = JTS.transform(bounds, transform);
                    double west = targetEnv.getMinX();
                    double north = targetEnv.getMaxY();
                    double east = targetEnv.getMaxX();
                    double south = targetEnv.getMinY();

                    if (west < -180) {
                        west = -180;
                    }
                    if (west > 180) {
                        west = 180;
                    }
                    if (north < -90) {
                        north = -90;
                    }
                    if (north > 90) {
                        north = 90;
                    }
                    if (east < -180) {
                        east = -180;
                    }
                    if (east > 180) {
                        east = 180;
                    }
                    if (south < -90) {
                        south = -90;
                    }
                    if (south > 90) {
                        south = 90;
                    }
                    west = 180.0 + west;
                    north = 90.0 + north;
                    east = 180.0 + east;
                    south = 90.0 + south;
                    double width = east - west;
                    double height = north - south;
                    if (width < 1) {
                        width = 1;
                    }
                    if (height < 1) {
                        height = 1;
                    }

                    int x = (int) ((double) canvasBounds.width * west / 360.0);
                    int y = (int) ((double) h * north / 180.0);
                    int fw = (int) ((double) canvasBounds.width * width / 360.0);
                    if (fw <= 1)
                        fw = 2;
                    int fh = (int) ((double) h * height / 180.0);
                    if (fh <= 1)
                        fh = 2;
                    int newy = h - y;
                    e.gc.setForeground(color);
                    e.gc.setBackground(color);
                    e.gc.setAlpha(80);
                    e.gc.fillRectangle(x, newy, fw, fh);

                    e.gc.drawLine(x + fw / 2, 0, x + fw / 2, newy);
                    // e.gc.drawLine(x + fw / 2, newy + fh, x + fw / 2, h);
                    //
                    e.gc.drawLine(0, newy + fh / 2, x, newy + fh / 2);
                    e.gc.drawLine(x + fw, newy + fh / 2, canvasBounds.width, newy + fh / 2);

                } catch (FactoryException e1) {
                    e1.printStackTrace();
                } catch (TransformException e1) {
                    e1.printStackTrace();
                }

            }
        });

        // Label fillLabel = new Label(parent, SWT.NONE);
        // fillLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        Group geonamesGroup = new Group(parent, SWT.NONE);
        geonamesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        geonamesGroup.setLayout(new GridLayout(4, false));
        geonamesGroup.setText("Geonames");

        Label availableLabel = new Label(geonamesGroup, SWT.NONE);
        availableLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
        availableLabel.setText("Available geonames data");

        URL folderUrl = Platform.getBundle(JGrassToolsPlugin.PLUGIN_ID).getResource("/geonamesfiles");
        String folderPath = null;
        try {
            folderPath = FileLocator.toFileURL(folderUrl).getPath();
            folderFile = new File(folderPath);

            String[] namesArray = loadGeonamesFiles();

            countriesCombo = new Combo(geonamesGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
            countriesCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            countriesCombo.setItems(namesArray);
            countriesCombo.select(0);
            countriesCombo.addSelectionListener(new SelectionAdapter(){
                public void widgetSelected( SelectionEvent e ) {
                    int selectionIndex = countriesCombo.getSelectionIndex();
                    String item = countriesCombo.getItem(selectionIndex);
                    final String file = folderFile.getAbsolutePath() + File.separator + item + ".txt";

                    IRunnableWithProgress operation = new IRunnableWithProgress(){
                        public void run( IProgressMonitor pm ) throws InvocationTargetException, InterruptedException {
                            try {
                                populatePlacesMap(placesMap, file);
                            } catch (FileNotFoundException e1) {
                                e1.printStackTrace();
                            } catch (IOException e1) {
                                e1.printStackTrace();
                            }
                        }
                    };
                    PlatformGIS.runInProgressDialog("Loading geonames data...", true, operation, true);
                }
            });

            Button addNewButton = new Button(geonamesGroup, SWT.PUSH);
            addNewButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
            addNewButton.setText("+");
            addNewButton.setToolTipText("Add a new geonames file (get it at http://download.geonames.org/export/dump/)");
            addNewButton.addSelectionListener(new SelectionAdapter(){
                public void widgetSelected( SelectionEvent e ) {
                    FileDialog fileDialog = new FileDialog(countriesCombo.getShell(), SWT.OPEN);
                    fileDialog.setFilterExtensions(new String[]{"*.txt"});
                    String newFilePath = fileDialog.open();
                    try {
                        if (newFilePath != null) {
                            File newFile = new File(newFilePath);
                            if (newFile.exists()) {
                                File copiedFile = new File(folderFile, newFile.getName());
                                FileUtils.copyFile(newFile, copiedFile);
                            }
                        }
                        String[] geonamesFiles = loadGeonamesFiles();
                        if (geonamesFiles.length > 0) {
                            countriesCombo.setItems(geonamesFiles);
                            countriesCombo.select(0);
                        } else {
                            countriesCombo.setItems(new String[]{"   --   "});
                        }
                    } catch (IOException e1) {
                        String message = "An error occurred while copying the new geonames file into the application.";
                        ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, JGrassToolsPlugin.PLUGIN_ID, e1);
                        e1.printStackTrace();
                    }
                }
            });

            Button removeButton = new Button(geonamesGroup, SWT.PUSH);
            removeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
            removeButton.setText("-");
            removeButton.setToolTipText("Remove a geonames file");
            removeButton.addSelectionListener(new SelectionAdapter(){
                public void widgetSelected( SelectionEvent e ) {
                    int selectionIndex = countriesCombo.getSelectionIndex();
                    String item = countriesCombo.getItem(selectionIndex);

                    try {
                        File namesFile = new File(folderFile, item + ".txt");
                        if (namesFile.exists()) {
                            FileUtils.forceDelete(namesFile);
                        }
                        String[] geonamesFiles = loadGeonamesFiles();
                        if (geonamesFiles.length > 0) {
                            countriesCombo.setItems(geonamesFiles);
                            countriesCombo.select(0);
                        } else {
                            countriesCombo.setItems(new String[]{"   --   "});
                        }
                    } catch (IOException e1) {
                        String message = "An error occurred while removing the old geonames file into the application.";
                        ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, JGrassToolsPlugin.PLUGIN_ID, e1);
                        e1.printStackTrace();
                    }
                }
            });

            Group placesGroup = new Group(geonamesGroup, SWT.NONE);
            GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false);
            layoutData.horizontalSpan = 4;
            placesGroup.setLayoutData(layoutData);
            placesGroup.setLayout(new GridLayout(2, false));
            placesGroup.setText("places");

            placesMap = new HashMap<String, Coordinate>(1000);
            populatePlacesMap(placesMap, first.getAbsolutePath());
            keySet = placesMap.keySet();

            final Text placesText = new Text(placesGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
            placesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            placesText.setText("");

            Button searchButton = new Button(placesGroup, SWT.PUSH);
            searchButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
            searchButton.setText("search");
            searchButton.addSelectionListener(new SelectionAdapter(){
                public void widgetSelected( SelectionEvent e ) {
                    String text = placesText.getText();
                    if (text.length() < 3) {
                        MessageBox msgBox = new MessageBox(placesText.getShell(), SWT.ICON_WARNING);
                        msgBox.setMessage("At least 3 letters are needed to do a search.");
                        msgBox.open();
                        return;
                    }

                    List<String> matchedList = new ArrayList<String>();
                    for( String name : keySet ) {
                        if (name.toLowerCase().matches(".*" + text.toLowerCase() + ".*")) {
                            matchedList.add(name);
                        }
                    }
                    String[] matchedArray = (String[]) matchedList.toArray(new String[matchedList.size()]);
                    Arrays.sort(matchedArray);
                    placesCombo.setItems(matchedArray);
                    placesCombo.select(0);
                }
            });

            placesCombo = new Combo(placesGroup, SWT.DROP_DOWN);
            placesCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            placesCombo.setItems(new String[]{ENTER_SEARCH_STRING});

            Button goButton = new Button(placesGroup, SWT.PUSH);
            goButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
            goButton.setText("go");
            goButton.addSelectionListener(new SelectionAdapter(){
                public void widgetSelected( SelectionEvent e ) {
                    IMap map = ApplicationGIS.getActiveMap();
                    if (map.getMapLayers().size() < 1) {
                        return;
                    }

                    ReferencedEnvelope bounds = map.getViewportModel().getBounds();
                    CoordinateReferenceSystem mapCrs = map.getViewportModel().getCRS();

                    try {
                        GeometryFactory gF = new GeometryFactory();
                        CoordinateReferenceSystem placeCrs = CRS.decode("EPSG:4326");
                        // transform coordinates before check
                        MathTransform transform = CRS.findMathTransform(placeCrs, mapCrs, true);
                        // jts geometry
                        int selectionIndex = placesCombo.getSelectionIndex();
                        String item = placesCombo.getItem(selectionIndex);
                        Coordinate coordinate = placesMap.get(item);
                        Point pt = gF.createPoint(coordinate);
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

            Query query = createQuery(sourceLayer, filter, targetLayer, attributeMap);
            if (attributeMap.isEmpty()) {
                targetLayer.setFilter(filter);
                return;
            }
            MathTransform mt = createMathTransform(sourceLayer, targetLayer);
            FeatureCollection<SimpleFeatureType, SimpleFeature> features = source
                    .getFeatures(query);
            SimpleFeatureType schema = targetLayer.getSchema();

           
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

        }
      
    }

    private MathTransform createMathTransform( ILayer sourceLayer, ILayer targetLayer ) {
        MathTransform temp;
        try {
            CoordinateReferenceSystem targetCRS = targetLayer.getCRS();
            CoordinateReferenceSystem sourceCRS = sourceLayer.getCRS();
            if (targetCRS.equals(sourceCRS))
                temp = null;
            else
                temp = CRS.findMathTransform(sourceCRS, targetCRS, true);
            if (temp == null || temp.isIdentity())
                temp = null;
        } catch (FactoryException e1) {
            ProjectPlugin.log("", e1); //$NON-NLS-1$
            temp = null;
        }
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

   
    if( GROUND.equals( context.getCRS()) ){
      return there;
    }
    try {
      MathTransform transform = CRS.findMathTransform( context.getCRS(), GROUND );
      return JTS.transform( there, null, transform );     
    } catch (FactoryException e) {
      e.printStackTrace();
      return null;
    } catch (TransformException e) {
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

   
    if( GROUND.equals( context.getCRS()) ){
      return ground;
    }
    try {
      MathTransform transform = CRS.findMathTransform( GROUND, context.getCRS() );
      return JTS.transform( ground, null, transform );     
    } catch (FactoryException e) {
      // I hate you
      return null;
    } catch (TransformException e) {
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

     *             transformation.
     */
    public ProcessingRegion reproject( CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient )
            throws Exception {

        MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, lenient);
        Envelope envelope = getEnvelope();
        Envelope targetEnvelope = JTS.transform(envelope, transform);

        return new ProcessingRegion(targetEnvelope.getMinX(), targetEnvelope.getMaxX(), targetEnvelope.getMinY(),
                targetEnvelope.getMaxY(), getRows(), getCols());
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

                         * finally reproject the map on the new grid.
                         */
                        JGrassRegion sourceRegion = jgMEnv.getActiveRegion();
                        CoordinateReferenceSystem sourceCrs = jgMEnv.getCoordinateReferenceSystem();
                        com.vividsolutions.jts.geom.Envelope sourceEnvelope = sourceRegion.getEnvelope();
                        MathTransform tr = CRS.findMathTransform(sourceCrs, crs);
                        com.vividsolutions.jts.geom.Envelope outputEnvelope = JTS.transform(sourceEnvelope, tr);

                        double west = outputEnvelope.getMinX();
                        double east = outputEnvelope.getMaxX();
                        double south = outputEnvelope.getMinY();
                        double north = outputEnvelope.getMaxY();

                        double xResolution = Double.parseDouble(xRes);
                        double yResolution = Double.parseDouble(yRes);
                        Coordinate tmp1 = new Coordinate(west, south);
                        Coordinate tmp2 = new Coordinate(west + xResolution, south + yResolution);
                        JTS.transform(tmp1, tmp1, tr);
                        JTS.transform(tmp2, tmp2, tr);
                        xResolution = tmp2.x - tmp1.x;
                        yResolution = tmp2.y - tmp1.y;

                        // if in metric, snap to integer bounds
                        int intWest = (int) Math.floor(west);
                        int intSouth = (int) Math.floor(south);
                        if (west - intWest < xResolution && south - intSouth < yResolution) {
                            west = intWest;
                            south = intSouth;
                        }

                        double w = east - west;
                        double h = north - south;
                        // modify the envelope to be in the requested resolution
                        double cols = Math.floor(w / xResolution) + 1.0;
                        double rows = Math.floor(h / yResolution) + 1.0;

                        double newEast = west + cols * xResolution;
                        double newNorth = south + rows * yResolution;

                        ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(west, newEast, south, newNorth, crs);

                        GridToEnvelopeMapper g2eMapper = new GridToEnvelopeMapper();
                        g2eMapper.setEnvelope(referencedEnvelope);
                        GridEnvelope2D gridEnvelope2D = new GridEnvelope2D(0, 0, (int) cols, (int) rows);
                        g2eMapper.setGridRange(gridEnvelope2D);
                        g2eMapper.setPixelAnchor(PixelInCell.CELL_CENTER);
                        MathTransform gridToEnvelopeTransform = g2eMapper.createTransform();

                        GridGeometry outputGridGeometry = new GridGeometry2D(gridEnvelope2D, gridToEnvelopeTransform, crs);

                        GridCoverage2D coverage2D = JGrassCatalogUtilities.getGridcoverageFromGrassraster(jgMEnv, sourceRegion);
                        // GrassCoverageReadParam gcReadParam = new
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

        GridStyle style = getStyle(context.getLayer());
        double[] gridSize=style.getGridSize();
    

        try{
            MathTransform mt = CRS.findMathTransform(DefaultGeographicCRS.WGS84, context.getCRS(), true);
       
            if( !mt.isIdentity() ){
                double x=gridSize[0]/2.0;
                double y=gridSize[1]/2.0;
                double[] toTransform=new double[]{-x,-y,x,y};
                double[] dest=new double[4];
                mt.transform(toTransform,0,dest,0,2);
                gridSize=new double[]{Math.abs(dest[2]-dest[0]), Math.abs(dest[3]-dest[1])};
            }
        }catch (Exception e) {
            MapGraphicPlugin.log("",e); //$NON-NLS-1$
        }
View Full Code Here

Examples of org.opengis.referencing.operation.MathTransform

    }

    private double[] worldClosest( int x1, int y1, ILayer layer ) throws FactoryException {
        Coordinate coord = layer.getMap().getViewportModel().pixelToWorld(x1, y1);
        CoordinateReferenceSystem crs = layer.getMap().getViewportModel().getCRS();
        MathTransform mt = CRS.findMathTransform(DefaultGeographicCRS.WGS84, crs);

        double[] gridSize = getStyle(layer).getGridSize();
        try{
       
            if( !mt.isIdentity() ){
                double tx=gridSize[0]/2.0;
                double ty=gridSize[1]/2.0;
                double[] toTransform=new double[]{-tx,-ty,tx,ty};
                double[] dest=new double[4];
                mt.transform(toTransform,0,dest,0,2);
                gridSize=new double[]{Math.abs(dest[2]-dest[0]), Math.abs(dest[3]-dest[1])};
            }
        }catch (Exception e) {
            MapGraphicPlugin.log("",e); //$NON-NLS-1$
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.