]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.imports/src/org/simantics/district/imports/DistrictImportUtils.java
c3ce3dad2084d175f63e261aa48483b61741b5ab
[simantics/district.git] / org.simantics.district.imports / src / org / simantics / district / imports / DistrictImportUtils.java
1 package org.simantics.district.imports;
2
3 import java.io.IOException;
4 import java.nio.file.Files;
5 import java.nio.file.Path;
6 import java.util.ArrayList;
7 import java.util.Collection;
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.Iterator;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.Optional;
14 import java.util.Set;
15 import java.util.concurrent.atomic.AtomicInteger;
16 import java.util.function.Function;
17
18 import org.apache.commons.csv.CSVFormat;
19 import org.apache.commons.csv.CSVParser;
20 import org.apache.commons.csv.CSVRecord;
21 import org.geotools.geometry.DirectPosition2D;
22 import org.geotools.referencing.CRS;
23 import org.opengis.geometry.DirectPosition;
24 import org.opengis.geometry.MismatchedDimensionException;
25 import org.opengis.referencing.FactoryException;
26 import org.opengis.referencing.NoSuchAuthorityCodeException;
27 import org.opengis.referencing.crs.CoordinateReferenceSystem;
28 import org.opengis.referencing.operation.MathTransform;
29 import org.opengis.referencing.operation.TransformException;
30 import org.simantics.Simantics;
31 import org.simantics.databoard.Bindings;
32 import org.simantics.db.Resource;
33 import org.simantics.db.WriteGraph;
34 import org.simantics.db.common.request.WriteRequest;
35 import org.simantics.db.exception.DatabaseException;
36 import org.simantics.db.layer0.util.Layer0Utils;
37 import org.simantics.district.network.DNEdgeBuilder;
38 import org.simantics.district.network.DistrictNetworkUtil;
39 import org.simantics.district.network.ontology.DistrictNetworkResource;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 import com.vividsolutions.jts.index.quadtree.Quadtree;
44
45 public class DistrictImportUtils {
46
47     private DistrictImportUtils() { }
48
49     private static final Logger LOGGER = LoggerFactory.getLogger(DistrictImportUtils.class);
50     
51     public static Resource importCSVAsLayer(Path csvFile) throws IOException {
52         
53         try (CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(Files.newBufferedReader(csvFile))) {
54             Map<String, Integer> header = parser.getHeaderMap();
55             System.out.println(header);
56         }
57         return null;
58     }
59     
60     public static Map<String, Integer> readCSVHeader(Path source, char delimiter, boolean firstAsHeader) throws IOException {
61         return readCSVHeader(source, CSVFormat.newFormat(delimiter), firstAsHeader);
62     }
63     
64     public static Map<String, Integer> readCSVHeader(Path source, CSVFormat format, boolean firstAsHeader) throws IOException {
65         if (firstAsHeader)
66             format = format.withFirstRecordAsHeader();
67         try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
68             return parser.getHeaderMap();
69         }
70     }
71
72     public static Map<String, Character> getSupportedCSVDelimiterFormats() {
73         Map<String, Character> delimiters = new HashMap<>();
74         delimiters.put("Comma", ',');
75         delimiters.put("Semicolon", ';');
76         delimiters.put("Tabulator", '\t');
77         return delimiters;
78     }
79
80     public static List<Map<String, String>> readRows(Path source, CSVFormat format, boolean firstAsHeader, int amount) throws IOException {
81         if (firstAsHeader)
82             format = format.withFirstRecordAsHeader();
83         try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
84             int start = 0;
85             List<Map<String, String>> results = new ArrayList<>(amount);
86             Iterator<CSVRecord> iter = parser.iterator();
87             while (start < amount && iter.hasNext()) {
88                 CSVRecord record = iter.next();
89                 results.add(record.toMap());
90                 start++;
91             }
92             return results;
93         }
94     }
95
96     public static List<CSVRecord> readRows(Path source, char delim, boolean firstAsHeader, int rowAmount) throws IOException {
97         List<CSVRecord> results = new ArrayList<>();
98         AtomicInteger count = new AtomicInteger(0);
99         consumeCSV(source, delim, firstAsHeader, t -> {
100             results.add(t);
101             int current = count.incrementAndGet();
102             return current < rowAmount;
103         });
104         return results;
105     }
106     
107     public static void consumeCSV(Path source, char delim, boolean firstAsHeader, Function<CSVRecord, Boolean> consumer) throws IOException {
108         CSVFormat format = CSVFormat.newFormat(delim);
109         if (firstAsHeader) {
110             format = format.withFirstRecordAsHeader();
111         }
112         try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
113             Iterator<CSVRecord> records = parser.iterator();
114             while (records.hasNext()) {
115                 Boolean cont = consumer.apply(records.next());
116                 if (!cont) {
117                     break;
118                 }
119             }
120         }
121     }
122
123     
124     public static Map<CSVHeader, List<String>> readCSVHeaderAndRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {
125         Map<CSVHeader, List<String>> results = new HashMap<>();
126         CSVFormat format = CSVFormat.newFormat(delimiter);
127         if (firstAsHeader)
128             format = format.withFirstRecordAsHeader();
129         try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
130             Map<String, Integer> headers = parser.getHeaderMap();
131             if (headers != null && !headers.isEmpty()) {
132                 for (int index = 0; index < headers.size(); index++) {
133                     for (String head : headers.keySet()) {
134                         results.put(new CSVHeader(head, index), new ArrayList<>());
135                     }
136                 }
137             }
138             
139             Iterator<CSVRecord> records = parser.iterator();
140             int rows = 0;
141             while (rows < amount && records.hasNext()) {
142                 CSVRecord record = records.next();
143                 for (int j = 0; j < record.size(); j++) {
144                     String value = record.get(j);
145                     String header = Integer.toString(j);
146                     CSVHeader csvHeader = new CSVHeader(header, j);
147                     List<String> vals = results.get(csvHeader);
148                     if (vals == null) {
149                         vals = new ArrayList<>();
150                         results.put(csvHeader, vals);
151                     }
152                     vals.add(value);
153                 }
154                 rows++;
155             }
156         }
157         return results;
158     }
159     
160     public static class CSVHeader {
161
162         private final String header;
163         private final int index;
164         
165         public CSVHeader(String header, int index) {
166             this.header = header;
167             this.index = index;
168         }
169
170         public String getHeader() {
171             return header;
172         }
173
174         public int getIndex() {
175             return index;
176         }
177         
178         @Override
179         public int hashCode() {
180             final int prime = 31;
181             int result = 1;
182             result = prime * result + ((header == null) ? 0 : header.hashCode());
183             result = prime * result + index;
184             return result;
185         }
186
187         @Override
188         public boolean equals(Object obj) {
189             if (this == obj)
190                 return true;
191             if (obj == null)
192                 return false;
193             if (getClass() != obj.getClass())
194                 return false;
195             CSVHeader other = (CSVHeader) obj;
196             if (header == null) {
197                 if (other.header != null)
198                     return false;
199             } else if (!header.equals(other.header))
200                 return false;
201             if (index != other.index)
202                 return false;
203             return true;
204         }
205     }
206
207     public static Collection<String> readDistinctValuesOfColumn(Path source, char delim, int mappingIndex) throws IOException {
208         Set<String> results = new HashSet<>();
209         CSVFormat format = CSVFormat.newFormat(delim);
210         try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
211             Iterator<CSVRecord> records = parser.iterator();
212             if (records.hasNext())
213                 records.next();
214             while (records.hasNext()) {
215                 CSVRecord row = records.next();
216                 String value = row.get(mappingIndex);
217                 results.add(value);
218             }
219         }
220         return results;
221     }
222
223     public static void importVertices(CSVImportModel model) throws NoSuchAuthorityCodeException, FactoryException, DatabaseException {
224
225         Path csvFile = model.getSource();
226         char delim = model.getDelimiter();
227
228         int xCoordColumnIndex = model.getXCoordIndex();
229         int yCoordColumnIndex = model.getYCoordIndex();
230         int zCoordColumnIndex = model.getZCoordIndex();
231         int altElevationIndex = model.getAlternativeElevationIndex();
232         int supplyTempColumnIndex = model.getSupplyTempIndex();
233         int returnTempColumnIndex = model.getReturnTempIndex();
234         int supplyPressureColumnIndex = model.getSupplyPressureIndex();
235         int returnPressureColumnIndex = model.getReturnPressureIndex();
236         int dpIndex = model.getDeltaPressureIndex();
237         int dtIndex = model.getDeltaTemperatureIndex();
238         int heatPowerIndex = model.getHeatPowerIndex();
239         int peakPowerIndex = model.getPeakPowerIndex();
240         int valvePositionIndex = model.getValvePositionIndx();
241         int nominalHeadMIndex = model.getNominalHeadMIndex();
242         int nominalHeadBIndex = model.getNominalHeadBIndex();
243         int nominalFlowIndex = model.getNominalFlowIndex();
244         int maximumHeadMIndex = model.getMaximumHeadMIndex();
245         int heatLoadDsIndex = model.getHeatLoadDsIndex();
246         int massFlowIndex = model.getMassFlowIndex();
247         int volFlowIndex = model.getVolFlowIndex();
248         int velocityIndex = model.getVelocityIndex();
249         int flowAreaIndex = model.getFlowAreaIndex();
250         int nominalPressureLossIndex = model.getNominalPressureLossIndex();
251         int addressIndex = model.getAddressIndex();
252         int regionIndex = model.getRegionIndex();
253         
254         int mappingColumn = model.getComponentMappingIndex();
255         int idColumn = model.getIdIndex();
256         
257         String sourceEPSGCRS = model.getSourceCRS();
258         
259         MathTransform transform = null;
260         boolean doTransform = false;
261         // if sourceEPSGCRS is empty || null then ignore transformation
262         if (sourceEPSGCRS != null && !sourceEPSGCRS.isEmpty()) {
263             CoordinateReferenceSystem sourceCRS = CRS.decode(sourceEPSGCRS);
264             CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
265             transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
266             doTransform = true;
267         }
268         final boolean actualDoTransform = doTransform;
269         final MathTransform actualTransform = transform;
270         
271         Simantics.getSession().syncRequest(new WriteRequest() {
272             
273             @Override
274             public void perform(WriteGraph graph) throws DatabaseException {
275                 try {
276                     Layer0Utils.setDependenciesIndexingDisabled(graph, true);
277                     graph.markUndoPoint();
278                     
279                     DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
280
281                     DistrictImportUtils.consumeCSV(csvFile, delim, true, (Function<CSVRecord, Boolean>) row -> {
282                         try {
283                             String mappingValue = row.get(mappingColumn);
284                             
285                             String xCoords = row.get(xCoordColumnIndex);
286                             String yCoords = row.get(yCoordColumnIndex);
287                             double xCoord = Double.parseDouble(xCoords);
288                             double yCoord = Double.parseDouble(yCoords);
289                             
290                             double z = 0;
291                             if (zCoordColumnIndex != -1) {
292                                 String zs = row.get(zCoordColumnIndex);
293                                 
294                                 if (!zs.isEmpty()) {
295                                     try {
296                                         z = Double.parseDouble(zs);
297                                     } catch (NumberFormatException e1) {
298                                         throw new DatabaseException(e1);
299                                     }
300                                 }
301                             }
302                             
303                             double[] coords;
304                             if (actualDoTransform) {
305                                 DirectPosition2D targetPos = new DirectPosition2D();
306                                 DirectPosition2D sourcePos = new DirectPosition2D(xCoord, yCoord);
307                                 DirectPosition res = actualTransform.transform(sourcePos, targetPos);
308                                 coords = res.getCoordinate();
309                             } else {
310                                 coords = new double[] { xCoord, yCoord };
311                             }
312                             
313                             // Switch to (longitude, latitude)
314                             flipAxes(coords);
315                             
316                             Resource vertex = DistrictNetworkUtil.createVertex(graph, model.getParentDiagram(), coords, z, model.getComponentMappings().get(mappingValue));
317                             
318                             writeStringValue(graph, row, idColumn, vertex, DN.HasId);
319                             
320                             writeValue(graph, row, altElevationIndex, vertex, DN.Vertex_HasAltElevation);
321                             
322                             writeValue(graph, row, supplyTempColumnIndex, vertex, DN.Vertex_HasSupplyTemperature);
323                             writeValue(graph, row, returnTempColumnIndex, vertex, DN.Vertex_HasReturnTemperature);
324                             writeValue(graph, row, supplyPressureColumnIndex, vertex, DN.Vertex_HasSupplyPressure);
325                             writeValue(graph, row, returnPressureColumnIndex, vertex, DN.Vertex_HasReturnPressure);
326                             writeValue(graph, row, dpIndex, vertex, DN.Vertex_HasDeltaPressure);
327                             writeValue(graph, row, dtIndex, vertex, DN.Vertex_HasDeltaTemperature);
328                             writeValue(graph, row, heatPowerIndex, vertex, DN.Vertex_HasHeatPower);
329                             writeValue(graph, row, peakPowerIndex, vertex, DN.Vertex_HasPeakPower);
330                             writeValue(graph, row, valvePositionIndex, vertex, DN.Vertex_HasValvePosition);
331                             writeValue(graph, row, nominalHeadMIndex, vertex, DN.Vertex_HasNominalHeadM);
332                             writeValue(graph, row, nominalHeadBIndex, vertex, DN.Vertex_HasNominalHeadB);
333                             writeValue(graph, row, nominalFlowIndex, vertex, DN.Vertex_HasNominalFlow);
334                             writeValue(graph, row, maximumHeadMIndex, vertex, DN.Vertex_HasMaximumHeadM);
335                             writeValue(graph, row, heatLoadDsIndex, vertex, DN.Vertex_HasHeatLoadDs);
336                             writeValue(graph, row, massFlowIndex, vertex, DN.Vertex_HasMassFlow);
337                             writeValue(graph, row, volFlowIndex, vertex, DN.Vertex_HasVolFlow);
338                             writeValue(graph, row, velocityIndex, vertex, DN.Vertex_HasVelocity);
339                             writeValue(graph, row, flowAreaIndex, vertex, DN.Vertex_HasFlowArea);
340                             writeValue(graph, row, nominalPressureLossIndex, vertex, DN.Vertex_HasNominalPressureLoss);
341                             writeStringValue(graph, row, addressIndex, vertex, DN.Vertex_HasAddress);
342                             writeStringValue(graph, row, regionIndex, vertex, DN.HasRegion);
343                         } catch (DatabaseException | MismatchedDimensionException | TransformException e) {
344                             throw new RuntimeException(e);
345                         }
346                         return true;
347                     });
348                     
349                 } catch (IOException e) {
350                     LOGGER.error("Could not import", e);
351                     throw new DatabaseException(e);
352                 } finally {
353                     Layer0Utils.setDependenciesIndexingDisabled(graph, false);
354                 }
355             }
356         });
357     }
358
359     public static void importEdges(CSVImportModel model) throws NoSuchAuthorityCodeException, FactoryException, DatabaseException {
360
361         Path csvFile = model.getSource();
362         char delim = model.getDelimiter();
363
364         Set<String> writtenIds = new HashSet<>();
365         
366         int startXCoordColumnIndex = model.getStartXCoordIndex();
367         int startYCoordColumnIndex = model.getStartYCoordIndex();
368         int startZValueColumnIndex = model.getStartZCoordIndex();
369         int endXCoordColumnIndex = model.getEndXCoordIndex();
370         int endYCoordColumnIndex = model.getEndYCoordIndex();
371         int endZValueColumnIndex = model.getEndZCoordIndex();
372         int diameterColumnIndex= model.getDiameterIndex();
373         int outerDiameterColumnIndex = model.getOuterDiamterIndex();
374         int nominalMassFlowIndex = model.getNominalMassFlowIndex();
375         int tGroundIndex = model.gettGroundIndex();
376         int edgeFlowAreaIndex = model.getEdgeFlowAreaIndex();
377         int kReturnIndex = model.getkReturnIndex();
378         int kSupplyIndex = model.getkSupplyIndex();
379         int lengthIndex = model.getLengthIndex();
380         int detailedGeometryIndex = model.getDetailedGeometryIndex();
381         int regionIndex = model.getRegionIndex();
382         
383         int mappingColumn = model.getComponentMappingIndex();
384         int idColumn = model.getIdIndex();
385         
386         double padding = model.getEdgePadding();
387
388         String sourceEPSGCRS = model.getSourceCRS();
389         
390         MathTransform transform = null;
391         boolean doTransform = false;
392         // if sourceEPSGCRS is empty || null then ignore transformation
393         if (sourceEPSGCRS != null && !sourceEPSGCRS.isEmpty()) {
394             CoordinateReferenceSystem sourceCRS = CRS.decode(sourceEPSGCRS);
395             CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
396             transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
397             doTransform = true;
398         }
399         final boolean actualDoTransform = doTransform;
400         final MathTransform actualTransform = transform;
401         
402         double halfPadding = padding / 2;
403         
404         Quadtree existingVertices = DistrictNetworkUtil.existingVertices(model.getParentDiagram(), halfPadding);
405
406         Simantics.getSession().syncRequest(new WriteRequest() {
407             
408             @Override
409             public void perform(WriteGraph graph) throws DatabaseException {
410                 try {
411                     Layer0Utils.setDependenciesIndexingDisabled(graph, true);
412                     graph.markUndoPoint();
413
414                     DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
415                     
416                     DistrictImportUtils.consumeCSV(csvFile, delim, true, row -> {
417                         try {
418                             
419                             String idValue = row.get(idColumn);
420                             if (!writtenIds.contains(idValue)) {
421                                 writtenIds.add(idValue);
422                                 String mappingValue = row.get(mappingColumn);
423                                 
424                                 String startXCoords = row.get(startXCoordColumnIndex);
425                                 String startYCoords = row.get(startYCoordColumnIndex);
426                                 String startZCoords = row.get(startZValueColumnIndex);
427                                 String endXCoords = row.get(endXCoordColumnIndex);
428                                 String endYCoords = row.get(endYCoordColumnIndex);
429                                 String endZCoords = row.get(endZValueColumnIndex);
430                                 
431                                 double startXCoord = Double.parseDouble(startXCoords); // make negative
432                                 double startYCoord = Double.parseDouble(startYCoords);
433                                 double startZCoord = Double.parseDouble(startZCoords);
434                                 
435                                 double endXCoord = Double.parseDouble(endXCoords); // make negative
436                                 double endYCoord = Double.parseDouble(endYCoords);
437                                 double endZCoord = Double.parseDouble(endZCoords);
438                                 
439                                 double[] startCoords;
440                                 double[] endCoords;
441                                 if (actualDoTransform) {
442                                     DirectPosition2D startTargetPos = new DirectPosition2D();
443                                     DirectPosition2D startSourcePos = new DirectPosition2D(startXCoord, startYCoord);
444                                     DirectPosition startRes = actualTransform.transform(startSourcePos, startTargetPos);
445                                     startCoords = startRes.getCoordinate();
446                                     
447                                     DirectPosition2D endTargetPos = new DirectPosition2D();
448                                     DirectPosition2D endSourcePos = new DirectPosition2D(endXCoord, endYCoord);
449                                     DirectPosition endRes = actualTransform.transform(endSourcePos, endTargetPos);
450                                     endCoords = endRes.getCoordinate();
451                                 } else {
452                                     startCoords = new double[] { startXCoord , startYCoord };
453                                     endCoords = new double[] { endXCoord , endYCoord };
454                                 }
455                                 
456                                 // Switch to (longitude, latitude)
457                                 flipAxes(startCoords);
458                                 flipAxes(endCoords);
459                                     
460                                 if ("6993003.00000".equals(idValue)) {
461                                     System.err.println("ghere we are!!");
462                                 }
463                                 
464                                 Optional<Resource> oedge = DNEdgeBuilder.create(graph, existingVertices, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, startZCoord, endCoords, endZCoord, new double[0], padding, true);
465                                 if (oedge.isPresent()) {
466                                     Resource edge = oedge.get();
467                                     
468                                     writeStringValue(graph, row, idColumn, edge, DN.HasId);
469                                     
470                                     writeValue(graph, row, diameterColumnIndex, edge, DN.Edge_HasDiameter);
471                                     writeValue(graph, row, outerDiameterColumnIndex, edge, DN.Edge_HasOuterDiameter);
472                                     writeValue(graph, row, nominalMassFlowIndex, edge, DN.Edge_HasNominalMassFlow);
473                                     writeValue(graph, row, tGroundIndex, edge, DN.Edge_HasTGround);
474                                     writeValue(graph, row, kReturnIndex, edge, DN.Edge_HasKReturn);
475                                     writeValue(graph, row, kSupplyIndex, edge, DN.Edge_HasKSupply);
476                                     writeValue(graph, row, edgeFlowAreaIndex, edge, DN.Edge_HasFlowArea);
477                                     writeValue(graph, row, lengthIndex, edge, DN.Edge_HasLength);
478                                     writeStringValue(graph, row, regionIndex, edge, DN.HasRegion);
479                                     writeDoubleArrayFromString(graph, row, detailedGeometryIndex, edge, DN.Edge_HasGeometry, actualTransform);
480                                 }
481                             }
482                             return true;
483                         } catch (DatabaseException | MismatchedDimensionException | TransformException e) {
484                             throw new RuntimeException(e);
485                         }
486                     });
487                 } catch (IOException e) {
488                     LOGGER.error("Could not import edges {}", model.getSource(), e);
489                 } finally {
490                     Layer0Utils.setDependenciesIndexingDisabled(graph, false);
491                 }
492             }
493         });
494     }
495     
496     private static void flipAxes(double[] coords) {
497         double tmp = coords[0];
498         coords[0] = coords[1];
499         coords[1] = tmp;
500     }
501
502     private static void writeValue(WriteGraph graph, CSVRecord row, int index, Resource subject, Resource relation) throws DatabaseException {
503         if (index != -1) {
504             String stringValue = row.get(index);
505             if (!stringValue.isEmpty()) {
506                 try {
507                     if (stringValue.startsWith("\"") && stringValue.endsWith("\"")) {
508                         stringValue = stringValue.substring(1, stringValue.length() - 1);
509                     }
510                     graph.claimLiteral(subject, relation, Double.parseDouble(stringValue), Bindings.DOUBLE);
511                 } catch (NumberFormatException e) {
512                     LOGGER.error("Could not parse {} {} {} {}", row, index, subject, relation, e);
513                     //throw new DatabaseException(e);
514                 }
515             }
516         }
517     }
518     
519     private static void writeStringValue(WriteGraph graph, CSVRecord row, int index, Resource subject, Resource relation) throws DatabaseException {
520         if (index != -1) {
521             String stringValue = row.get(index);
522             if (!stringValue.isEmpty()) {
523                 try {
524                     graph.claimLiteral(subject, relation, stringValue, Bindings.STRING);
525                 } catch (NumberFormatException e) {
526                     throw new DatabaseException(e);
527                 }
528             }
529         }
530     }
531
532     private static void writeDoubleArrayFromString(WriteGraph graph, CSVRecord row, int index, Resource subject, Resource relation, MathTransform actualTransform) throws DatabaseException, MismatchedDimensionException, TransformException {
533         if (index != -1) {
534             String stringValue = row.get(index);
535             if (!stringValue.isEmpty()) {
536                 if (stringValue.startsWith("\"") && stringValue.endsWith("\"")) {
537                     stringValue = stringValue.substring(1, stringValue.length() - 1);
538                 }
539                 String[] coordPairs = stringValue.split(";");
540                 ArrayList<Double> dd = new ArrayList<>(coordPairs.length * 2);
541                 for (int i = 0; i < coordPairs.length; i++) {
542                     String coordPair = coordPairs[i];
543                     String[] p = coordPair.split(" ");
544                     double x = Double.parseDouble(p[0]);
545                     double y = Double.parseDouble(p[1]);
546                     if (actualTransform != null) {
547                         DirectPosition2D targetPos = new DirectPosition2D();
548                         DirectPosition2D sourcePos = new DirectPosition2D(y, x);
549                         DirectPosition res = actualTransform.transform(sourcePos, targetPos);
550                         double[] coords = res.getCoordinate();
551                         x = coords[1];
552                         y = coords[0];
553                     }
554                     dd.add(x);
555                     dd.add(y);
556                 }
557                 double[] detailedGeometryCoords = new double[dd.size()];
558                 for (int i = 0; i < dd.size(); i++) {
559                     double d = dd.get(i);
560                     detailedGeometryCoords[i] = d;
561                 }
562                 try {
563                     graph.claimLiteral(subject, relation, detailedGeometryCoords, Bindings.DOUBLE_ARRAY);
564                 } catch (NumberFormatException e) {
565                     throw new DatabaseException(e);
566                 }
567             }
568         }
569     }
570 }