Subversion Repositories hibernate-spatial

Rev

Rev 130 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 130 Rev 200
Line 1... Line 1...
1
/**
1
/*
2
 * $Id: GeometryFactoryHelper.java 130 2009-04-01 22:13:06Z maesenka $
2
 * $Id: GeometryFactoryHelper.java 200 2010-03-31 19:52:12Z maesenka $
3
 *
3
 *
4
 * This file is part of Hibernate Spatial, an extension to the
4
 * This file is part of Hibernate Spatial, an extension to the
5
 * hibernate ORM solution for geographic data.
5
 * hibernate ORM solution for geographic data.
6
 *
-
 
7
 * Copyright © 2007 Geovise BVBA
-
 
8
 *
6
 *
9
 * This work was partially supported by the European Commission,
7
 * Copyright © 2007-2010 Geovise BVBA
10
 * under the 6th Framework Programme, contract IST-2-004688-STP.
-
 
11
 *
8
 *
12
 * This library is free software; you can redistribute it and/or
9
 * This library is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU Lesser General Public
10
 * modify it under the terms of the GNU Lesser General Public
14
 * License as published by the Free Software Foundation; either
11
 * License as published by the Free Software Foundation; either
15
 * version 2.1 of the License, or (at your option) any later version.
12
 * version 2.1 of the License, or (at your option) any later version.
Line 25... Line 22...
25
 *
22
 *
26
 * For more information, visit: http://www.hibernatespatial.org/
23
 * For more information, visit: http://www.hibernatespatial.org/
27
 */
24
 */
28
package org.hibernatespatial.cfg;
25
package org.hibernatespatial.cfg;
29
 
26
 
-
 
27
import com.vividsolutions.jts.geom.PrecisionModel;
30
import java.util.Map;
28
import org.hibernatespatial.mgeom.MGeometryFactory;
31
 
-
 
32
import org.slf4j.Logger;
29
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
30
import org.slf4j.LoggerFactory;
34
import org.hibernatespatial.mgeom.MGeometryFactory;
-
 
35
 
31
 
36
import com.vividsolutions.jts.geom.PrecisionModel;
32
import java.util.Map;
37
 
33
 
-
 
34
/**
-
 
35
 * Factory for creating a <code>GeometryFactory</code> given a map of
-
 
36
 * configuration parameters.
-
 
37
 *
-
 
38
 * @author Karel Maesen, Geovise BVBA
-
 
39
 */
38
public class GeometryFactoryHelper {
40
public class GeometryFactoryHelper {
39
 
41
 
40
	private static Logger logger = LoggerFactory.getLogger(GeometryFactoryHelper.class);
42
    private static Logger logger = LoggerFactory.getLogger(GeometryFactoryHelper.class);
41
 
43
 
42
	public static MGeometryFactory createGeometryFactory(Map map) {
44
    public static MGeometryFactory createGeometryFactory(Map map) {
43
 
45
 
44
		if (map == null) {
46
        if (map == null) {
45
			return new MGeometryFactory();
47
            return new MGeometryFactory();
46
		}
48
        }
47
		String precisionModelName = null;
49
        String precisionModelName = null;
48
		Double scale = null;
50
        Double scale = null;
49
		if (map.containsKey(HSProperty.PRECISION_MODEL.toString())) {
51
        if (map.containsKey(HSProperty.PRECISION_MODEL.toString())) {
50
			precisionModelName = (String) map.get(HSProperty.PRECISION_MODEL
52
            precisionModelName = (String) map.get(HSProperty.PRECISION_MODEL
51
					.toString());
53
                    .toString());
52
		}
54
        }
53
		if (map.containsKey(HSProperty.PRECISION_MODEL_SCALE.toString())) {
55
        if (map.containsKey(HSProperty.PRECISION_MODEL_SCALE.toString())) {
54
			scale = Double.parseDouble(((String) map
56
            scale = Double.parseDouble(((String) map
55
					.get(HSProperty.PRECISION_MODEL_SCALE.toString())));
57
                    .get(HSProperty.PRECISION_MODEL_SCALE.toString())));
56
		}
58
        }
57
		if (scale != null && !scale.isNaN() && precisionModelName != null
59
        if (scale != null && !scale.isNaN() && precisionModelName != null
58
				&& precisionModelName.equalsIgnoreCase("FIXED")) {
60
                && precisionModelName.equalsIgnoreCase("FIXED")) {
59
			return new MGeometryFactory(new PrecisionModel(scale));
61
            return new MGeometryFactory(new PrecisionModel(scale));
60
		}
62
        }
61
		if (precisionModelName == null) {
63
        if (precisionModelName == null) {
62
			return new MGeometryFactory();
64
            return new MGeometryFactory();
63
		}
65
        }
64
		if (precisionModelName.equalsIgnoreCase("FIXED")) {
66
        if (precisionModelName.equalsIgnoreCase("FIXED")) {
65
			return new MGeometryFactory(
67
            return new MGeometryFactory(
66
					new PrecisionModel(PrecisionModel.FIXED));
68
                    new PrecisionModel(PrecisionModel.FIXED));
67
		}
69
        }
68
		if (precisionModelName.equalsIgnoreCase("FLOATING")) {
70
        if (precisionModelName.equalsIgnoreCase("FLOATING")) {
69
			return new MGeometryFactory(new PrecisionModel(
71
            return new MGeometryFactory(new PrecisionModel(
70
					PrecisionModel.FLOATING));
72
                    PrecisionModel.FLOATING));
71
		}
73
        }
72
		if (precisionModelName.equalsIgnoreCase("FLOATING_SINGLE")) {
74
        if (precisionModelName.equalsIgnoreCase("FLOATING_SINGLE")) {
73
			return new MGeometryFactory(new PrecisionModel(
75
            return new MGeometryFactory(new PrecisionModel(
74
					PrecisionModel.FLOATING_SINGLE));
76
                    PrecisionModel.FLOATING_SINGLE));
75
		}
77
        }
76
		logger.warn("Configured for PrecisionModel: " + precisionModelName
78
        logger.warn("Configured for PrecisionModel: " + precisionModelName
77
				+ " but don't know how to instantiate.");
79
                + " but don't know how to instantiate.");
78
		logger.warn("Reverting to default GeometryModel");
80
        logger.warn("Reverting to default GeometryModel");
79
		return new MGeometryFactory();
81
        return new MGeometryFactory();
80
	}
82
    }
81
 
83
 
82
}
84
}