Revision 218 org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.buffer/src/main/java/org/gvsig/geoprocess/algorithm/buffer/FieldDistance.java
FieldDistance.java | ||
---|---|---|
20 | 20 |
*/ |
21 | 21 |
package org.gvsig.geoprocess.algorithm.buffer; |
22 | 22 |
|
23 |
|
|
24 | 23 |
import org.cresques.cts.IProjection; |
25 | 24 |
|
26 | 25 |
import org.gvsig.fmap.dal.feature.Feature; |
27 |
import org.gvsig.geoprocess.GeoProcessLocator; |
|
28 | 26 |
|
29 | 27 |
/** |
30 | 28 |
* Computes a constant size of each geometry built |
29 |
* |
|
31 | 30 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
32 | 31 |
*/ |
33 |
public class FieldDistance implements IDistance { |
|
34 |
private Feature feature = null; |
|
35 |
private int attributePosition = 0; |
|
36 |
|
|
37 |
public FieldDistance(int attributePosition) { |
|
38 |
this.attributePosition = attributePosition; |
|
39 |
} |
|
40 |
|
|
41 |
public void setFeature(Feature feature) { |
|
42 |
this.feature = feature; |
|
43 |
} |
|
44 |
|
|
45 |
/* |
|
46 |
* (non-Javadoc) |
|
47 |
* @see org.gvsig.geoprocess.algorithm.buffer.IDistance#getBufferDistance(double, org.cresques.cts.IProjection, int, int) |
|
48 |
*/ |
|
49 |
public double getBufferDistance(double distance, IProjection projection, |
|
50 |
int distanceUnits, int mapUnits) { |
|
51 |
double attr = 0D; |
|
52 |
Object obj = feature.get(attributePosition); |
|
53 |
if(obj instanceof Double) |
|
54 |
attr = ((Double)obj).doubleValue(); |
|
55 |
else if(obj instanceof Integer) |
|
56 |
attr = ((Integer)obj).doubleValue(); |
|
57 |
else if(obj instanceof Float) |
|
58 |
attr = ((Float)obj).doubleValue(); |
|
59 |
else return 0; |
|
60 |
|
|
61 |
return GeoProcessLocator.getGeoProcessManager().getInInternalUnits( |
|
62 |
attr, projection, distanceUnits, mapUnits); |
|
63 |
} |
|
32 |
public class FieldDistance extends AbstractDistance { |
|
64 | 33 |
|
65 |
} |
|
34 |
private Feature feature = null; |
|
35 |
private int attributePosition = 0; |
|
36 |
|
|
37 |
public FieldDistance(int attributePosition) { |
|
38 |
this.attributePosition = attributePosition; |
|
39 |
} |
|
40 |
|
|
41 |
public void setFeature(Feature feature) { |
|
42 |
this.feature = feature; |
|
43 |
} |
|
44 |
|
|
45 |
/* |
|
46 |
* (non-Javadoc) |
|
47 |
* |
|
48 |
* @see |
|
49 |
* org.gvsig.geoprocess.algorithm.buffer.IDistance#getBufferDistance(double, |
|
50 |
* org.cresques.cts.IProjection, int, int) |
|
51 |
*/ |
|
52 |
public double getBufferDistance(double distance, IProjection projection, |
|
53 |
int distanceUnits, int mapUnits) { |
|
54 |
double attr = 0D; |
|
55 |
Object obj = feature.get(attributePosition); |
|
56 |
if (obj instanceof Double) |
|
57 |
attr = ((Double) obj).doubleValue(); |
|
58 |
else |
|
59 |
if (obj instanceof Integer) |
|
60 |
attr = ((Integer) obj).doubleValue(); |
|
61 |
else |
|
62 |
if (obj instanceof Float) |
|
63 |
attr = ((Float) obj).doubleValue(); |
|
64 |
else |
|
65 |
return 0; |
|
66 |
|
|
67 |
return getInInternalUnits(attr, projection, distanceUnits, mapUnits); |
|
68 |
} |
|
69 |
|
|
70 |
} |
Also available in: Unified diff