Revision 34140

View differences:

branches/v2_0_0_prep/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/impl/DefaultGeometryManagerTest.java
36 36
import junit.framework.TestCase;
37 37

  
38 38
import org.cresques.cts.ICoordTrans;
39

  
39 40
import org.gvsig.fmap.geom.Geometry;
40 41
import org.gvsig.fmap.geom.handler.Handler;
41 42
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
......
377 378
			return null;
378 379
		}
379 380

  
381
        public double area() throws GeometryOperationNotSupportedException,
382
            GeometryOperationException {
383
            // TODO Auto-generated method stub
384
            return 0;
385
        }
386

  
387
        public double perimeter()
388
            throws GeometryOperationNotSupportedException,
389
            GeometryOperationException {
390
            // TODO Auto-generated method stub
391
            return 0;
392
        }
393

  
380 394
	}
381 395
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/perimeter/Perimeter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.geom.operation.perimeter;
23

  
24
import org.gvsig.fmap.geom.Geometry;
25
import org.gvsig.fmap.geom.GeometryLocator;
26
import org.gvsig.fmap.geom.operation.GeometryOperation;
27
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
28
import org.gvsig.fmap.geom.operation.GeometryOperationException;
29
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
30

  
31

  
32
/**
33
 * @author gvSIG Team
34
 * @version $Id$
35
 *
36
 */
37
public class Perimeter extends GeometryOperation {
38
    public static final String NAME = "perimeter";
39
    public static final int CODE = GeometryLocator.getGeometryManager().
40
        getGeometryOperationCode(NAME);
41
    
42
    public Object invoke(Geometry geom, GeometryOperationContext ctx)
43
        throws GeometryOperationException {
44
        com.vividsolutions.jts.geom.Geometry jtsGeometry;
45
        try {
46
            jtsGeometry = (com.vividsolutions.jts.geom.Geometry)geom.invokeOperation("toJTS", null);
47
        } catch (GeometryOperationNotSupportedException e) {
48
           throw new GeometryOperationException(e);
49
        }
50
        return new Double(jtsGeometry.getLength());
51
    }
52

  
53
    public int getOperationIndex() {
54
        return CODE;
55
    }
56
}
0 57

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/impl/DefaultGeometryOperationLibrary.java
27 27
 
28 28
package org.gvsig.fmap.geom.operation.impl;
29 29

  
30
import org.gvsig.fmap.geom.Geometry.TYPES;
30 31
import org.gvsig.fmap.geom.GeometryLibrary;
31 32
import org.gvsig.fmap.geom.GeometryLocator;
32 33
import org.gvsig.fmap.geom.GeometryManager;
33
import org.gvsig.fmap.geom.Geometry.TYPES;
34
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary;
34
import org.gvsig.fmap.geom.operation.area.Area;
35 35
import org.gvsig.fmap.geom.operation.distance.PointDistance;
36 36
import org.gvsig.fmap.geom.operation.ensureOrientation.EnsureOrientation;
37 37
import org.gvsig.fmap.geom.operation.flip.Flip;
......
39 39
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB;
40 40
import org.gvsig.fmap.geom.operation.fromwkt.FromWKT;
41 41
import org.gvsig.fmap.geom.operation.isCCW.IsCCW;
42
import org.gvsig.fmap.geom.operation.perimeter.Perimeter;
42 43
import org.gvsig.fmap.geom.operation.relationship.Contains;
43 44
import org.gvsig.fmap.geom.operation.relationship.Crosses;
44 45
import org.gvsig.fmap.geom.operation.relationship.Disjoint;
......
97 98
		geometryManager.registerGeometryOperation(FromJTS.NAME, new FromJTS());
98 99
		geometryManager.registerGeometryOperation(PointGetAngle.NAME, new PointGetAngle());
99 100
		geometryManager.registerGeometryOperation(Out.NAME, new Out());
101
		geometryManager.registerGeometryOperation(Area.NAME, new Area());
102
	      geometryManager.registerGeometryOperation(Perimeter.NAME, new Perimeter());
100 103
	}	
101 104
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/area/Area.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.geom.operation.area;
23

  
24
import org.gvsig.fmap.geom.Geometry;
25
import org.gvsig.fmap.geom.GeometryLocator;
26
import org.gvsig.fmap.geom.operation.GeometryOperation;
27
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
28
import org.gvsig.fmap.geom.operation.GeometryOperationException;
29
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
30

  
31

  
32
/**
33
 * @author gvSIG Team
34
 * @version $Id$
35
 *
36
 */
37
public class Area extends GeometryOperation {
38
    public static final String NAME = "area";
39
    public static final int CODE = GeometryLocator.getGeometryManager().
40
        getGeometryOperationCode(NAME);
41
    
42
    public Object invoke(Geometry geom, GeometryOperationContext ctx)
43
        throws GeometryOperationException {
44
        com.vividsolutions.jts.geom.Geometry jtsGeometry;
45
        try {
46
            jtsGeometry = (com.vividsolutions.jts.geom.Geometry)geom.invokeOperation("toJTS", null);
47
        } catch (GeometryOperationNotSupportedException e) {
48
           throw new GeometryOperationException(e);
49
        }
50
        return new Double(jtsGeometry.getArea());
51
    }
52

  
53
    public int getOperationIndex() {
54
        return CODE;
55
    }
56
}
0 57

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/Geometry2D.java
35 35
import java.awt.geom.Rectangle2D;
36 36

  
37 37
import org.cresques.cts.ICoordTrans;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

  
38 41
import org.gvsig.fmap.geom.Geometry;
39 42
import org.gvsig.fmap.geom.GeometryLocator;
40 43
import org.gvsig.fmap.geom.GeometryManager;
......
50 53
import org.gvsig.fmap.geom.primitive.Point;
51 54
import org.gvsig.fmap.geom.type.GeometryType;
52 55
import org.gvsig.fmap.geom.util.Converter;
53
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55 56

  
56 57
/**
57 58
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
......
574 575
		GeometryOperationContext geometryOperationContext = new GeometryOperationContext();
575 576
		geometryOperationContext.setAttribute("JTSGeometry", point);
576 577
		return (Point)this.invokeOperation("fromJTS", geometryOperationContext);		
577
	}	
578
	}
579
	
580
	public double area() throws GeometryOperationNotSupportedException, GeometryOperationException
581
	{
582
	    //Using get getJTS method instead of use the "toJTS" operation just for performance
583
	    return getJTS().getArea();
584
	}
585
    
586
    public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException
587
    {
588
      //Using get getJTS method instead of use the "toJTS" operation just for performance
589
        return getJTS().getLength();
590
    }
578 591
}
579 592

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/DefaultGeometryManager.java
34 34
import java.util.List;
35 35
import java.util.Map;
36 36

  
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

  
37 40
import org.gvsig.fmap.geom.Geometry;
41
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
42
import org.gvsig.fmap.geom.Geometry.TYPES;
38 43
import org.gvsig.fmap.geom.GeometryException;
39 44
import org.gvsig.fmap.geom.GeometryLocator;
40 45
import org.gvsig.fmap.geom.GeometryManager;
41
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
42
import org.gvsig.fmap.geom.Geometry.TYPES;
43 46
import org.gvsig.fmap.geom.aggregate.MultiCurve;
44 47
import org.gvsig.fmap.geom.aggregate.MultiSurface;
45 48
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
......
63 66
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
64 67
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
65 68
import org.gvsig.fmap.geom.type.impl.DefaultGeometryType;
66
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
68 69

  
69 70
/**
70 71
 * Default implementation for the {@link GeometryManager}. When the
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/AbstractPrimitive.java
8 8

  
9 9
import org.cresques.cts.ICoordTrans;
10 10
import org.cresques.cts.IProjection;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13

  
11 14
import org.gvsig.fmap.geom.Geometry;
12 15
import org.gvsig.fmap.geom.GeometryLocator;
13 16
import org.gvsig.fmap.geom.GeometryManager;
......
25 28
import org.gvsig.fmap.geom.primitive.Primitive;
26 29
import org.gvsig.fmap.geom.type.GeometryType;
27 30
import org.gvsig.fmap.geom.util.Converter;
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30 31

  
31 32

  
32 33
/**
......
672 673
		GeometryOperationContext geometryOperationContext = new GeometryOperationContext();
673 674
		geometryOperationContext.setAttribute("JTSGeometry", point);
674 675
		return (Point)this.invokeOperation("fromJTS", geometryOperationContext);		
675
	}		
676
	}	
677
	
678
	public double area() throws GeometryOperationNotSupportedException, GeometryOperationException
679
    {
680
        //Using get getJTS method instead of use the "toJTS" operation just for performance
681
        return getJTS().getArea();
682
    }
683
    
684
    public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException
685
    {
686
      //Using get getJTS method instead of use the "toJTS" operation just for performance
687
        return getJTS().getLength();
688
    }
676 689
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Curve2DZ.java
41 41
package org.gvsig.fmap.geom.primitive.impl;
42 42

  
43 43
import org.cresques.cts.IProjection;
44

  
44 45
import org.gvsig.fmap.geom.Geometry;
45 46
import org.gvsig.fmap.geom.primitive.Curve;
46 47
import org.gvsig.fmap.geom.primitive.FShape;
......
53 54
 * @author Vicente Caballero Navarro
54 55
 */
55 56
public class Curve2DZ extends Curve2D implements Curve {
56
	private static final long serialVersionUID = 3431077088722464314L;
57
	double[] pZ = null;
57
    private static final long serialVersionUID = 3431077088722464314L;
58
    double[] pZ = null;
58 59

  
59
	/**
60
	 * The constructor with the GeometryType like and argument 
61
	 * is used by the {@link GeometryType}{@link #create()}
62
	 * to create the geometry
63
	 * @param type
64
	 * The geometry type
65
	 */
66
	public Curve2DZ(GeometryType geometryType) {
67
		super(geometryType);
68
	}
60
    /**
61
     * The constructor with the GeometryType like and argument 
62
     * is used by the {@link GeometryType}{@link #create()}
63
     * to create the geometry
64
     * @param type
65
     * The geometry type
66
     */
67
    public Curve2DZ(GeometryType geometryType) {
68
        super(geometryType);
69
    }
69 70

  
70
	/**
71
	 * Constructor used in the {@link Geometry#cloneGeometry()} method
72
	 * @param id
73
	 * @param projection
74
	 * @param gpx
75
	 * @param pZ
76
	 */
77
	Curve2DZ(GeometryType geometryType, String id, IProjection projection, GeneralPathX gpx,
78
			double[] pZ) {
79
		super(geometryType, id, projection, gpx);
80
		this.pZ = pZ;
81
	}	
71
    /**
72
     * Constructor used in the {@link Geometry#cloneGeometry()} method
73
     * @param id
74
     * @param projection
75
     * @param gpx
76
     * @param pZ
77
     */
78
    Curve2DZ(GeometryType geometryType, String id, IProjection projection, GeneralPathX gpx,
79
        double[] pZ) {
80
        super(geometryType, id, projection, gpx);
81
        this.pZ = pZ;
82
    }	
82 83

  
83
	/*
84
	 * (non-Javadoc)
85
	 * @see org.gvsig.fmap.geom.primitive.impl.Curve2D#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
86
	 */
87
	public void setGeneralPath(GeneralPathX generalPathX) {
88
		super.setGeneralPath(generalPathX);
89
		pZ = new double[generalPathX.getNumCoords()];
90
	}
84
    /*
85
     * (non-Javadoc)
86
     * @see org.gvsig.fmap.geom.primitive.impl.Curve2D#setGeneralPath(org.gvsig.fmap.geom.primitive.GeneralPathX)
87
     */
88
    public void setGeneralPath(GeneralPathX generalPathX) {
89
        super.setGeneralPath(generalPathX);
90
        pZ = new double[generalPathX.getNumCoords()];
91
    }
91 92

  
92
	/*
93
	 * (non-Javadoc)
94
	 * @see org.gvsig.fmap.geom.primitive.impl.Curve2D#getShapeType()
95
	 */
96
	public int getShapeType() {
97
		return TYPES.CURVE;
98
	}
93
    /*
94
     * (non-Javadoc)
95
     * @see org.gvsig.fmap.geom.primitive.impl.Curve2D#getShapeType()
96
     */
97
    public int getShapeType() {
98
        return TYPES.CURVE;
99
    }
99 100

  
100
	/*
101
	 * (non-Javadoc)
102
	 * @see org.gvsig.fmap.geom.primitive.impl.Curve2D#cloneFShape()
103
	 */
104
	public FShape cloneFShape() {
105
		return new Curve2DZ(getGeometryType(), id, projection, (GeneralPathX) gp.clone(),
106
				(double[]) pZ);
107
	}
101
    /*
102
     * (non-Javadoc)
103
     * @see org.gvsig.fmap.geom.primitive.impl.Curve2D#cloneFShape()
104
     */
105
    public FShape cloneFShape() {
106
        return new Curve2DZ(getGeometryType(), id, projection, (GeneralPathX) gp.clone(),
107
            (double[]) pZ);
108
    }
108 109

  
109
	/*
110
	 * (non-Javadoc)
111
	 * @see org.gvsig.fmap.geom.primitive.impl.Curve2D#setCoordinateAt(int, int, double)
112
	 */
113
	public void setCoordinateAt(int index, int dimension, double value) {
114
		if (dimension == 2){
115
			pZ[index] = value;
116
		}else{
117
			super.setCoordinateAt(index, dimension, value);
118
		}
119
	}
110
    /*
111
     * (non-Javadoc)
112
     * @see org.gvsig.fmap.geom.primitive.impl.Curve2D#setCoordinateAt(int, int, double)
113
     */
114
    public void setCoordinateAt(int index, int dimension, double value) {
115
        if (dimension == 2){
116
            pZ[index] = value;
117
        }else{
118
            super.setCoordinateAt(index, dimension, value);
119
        }
120
    }
121

  
122
    public double getCoordinateAt(int index, int dimension) {
123
        if (dimension == 2){
124
            return pZ[index];
125
        }else{
126
            return super.getCoordinateAt(index, dimension);
127
        }            
128
    }   
120 129
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Surface2DZ.java
41 41
package org.gvsig.fmap.geom.primitive.impl;
42 42

  
43 43
import org.cresques.cts.IProjection;
44

  
44 45
import org.gvsig.fmap.geom.Geometry;
45 46
import org.gvsig.fmap.geom.primitive.FShape;
46 47
import org.gvsig.fmap.geom.primitive.GeneralPathX;
......
115 116
		pZ = new double[generalPathX.getNumCoords()];
116 117
	}
117 118
	
118
	
119
    public double getCoordinateAt(int index, int dimension) {
120
        if (dimension == 2){
121
            return pZ[index];
122
        }else{
123
            return super.getCoordinateAt(index, dimension);
124
        }            
125
    }	
119 126
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/Geometry.java
34 34
import java.io.Serializable;
35 35

  
36 36
import org.cresques.cts.ICoordTrans;
37

  
37 38
import org.gvsig.fmap.geom.handler.Handler;
38 39
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
39 40
import org.gvsig.fmap.geom.operation.GeometryOperationException;
......
620 621
			GeometryOperationException;
621 622

  
622 623
	public Point centroid() throws GeometryOperationNotSupportedException, GeometryOperationException;
624
	
625
	public double area() throws GeometryOperationNotSupportedException, GeometryOperationException;
626
	
627
	public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException;
623 628
}

Also available in: Unified diff