Revision 21841 branches/Mobile_Compatible_Hito_1/libFMap/src-file/org/gvsig/data/datastores/vectorial/file/shp_jni/simplify/DiskShpDriver.java
DiskShpDriver.java | ||
---|---|---|
7 | 7 |
import java.util.HashMap; |
8 | 8 |
|
9 | 9 |
import org.apache.log4j.Logger; |
10 |
import org.gvsig.data.datastores.vectorial.file.shp_jni.FMapFastGeometry; |
|
10 | 11 |
import org.gvsig.data.datastores.vectorial.file.shp_mem.simplify.MemoryShpDriver; |
11 | 12 |
import org.gvsig.data.datastores.vectorial.file.shp_util.SHP; |
13 |
import org.gvsig.fmap.geom.Geometry; |
|
14 |
import org.gvsig.fmap.geom.GeometryFactory; |
|
15 |
import org.gvsig.fmap.geom.GeometryManager; |
|
16 |
import org.gvsig.fmap.geom.primitive.FShape; |
|
17 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
18 |
import org.gvsig.fmap.geom.primitive.NullGeometry; |
|
12 | 19 |
|
13 |
import es.prodevelop.gvsig.mobile.fmap.core.FMapFastGeometry; |
|
14 |
import es.prodevelop.gvsig.mobile.fmap.core.FNullGeometry; |
|
15 |
import es.prodevelop.gvsig.mobile.fmap.core.FShape; |
|
16 |
import es.prodevelop.gvsig.mobile.fmap.core.GeneralPathX; |
|
17 |
import es.prodevelop.gvsig.mobile.fmap.core.IGeometry; |
|
18 |
import es.prodevelop.gvsig.mobile.fmap.core.ShapeFactory; |
|
19 |
import es.prodevelop.gvsig.mobile.fmap.driver.ITableDefinition; |
|
20 | 20 |
import es.prodevelop.gvsig.mobile.fmap.driver.vect.shp.ShpReader; |
21 |
import es.prodevelop.gvsig.mobile.fmap.util.Utils; |
|
22 | 21 |
|
23 | 22 |
/** |
24 | 23 |
* SHP driver via JNI when the file does not have to be loaded into memory. |
... | ... | |
78 | 77 |
* |
79 | 78 |
* @throws IOException |
80 | 79 |
*/ |
81 |
public IGeometry getShape(int index) throws IOException {
|
|
80 |
public Geometry getShape(int index) throws IOException { |
|
82 | 81 |
|
83 | 82 |
double[] shp = ShpReader.getShapeWithBox(handler, index); |
84 | 83 |
|
85 | 84 |
if (shp == null) |
86 |
return new FNullGeometry();
|
|
85 |
return new NullGeometry(); |
|
87 | 86 |
addBoxToHash(index, shp[0], shp[1], shp[2], shp[3]); |
88 | 87 |
|
89 | 88 |
FMapFastGeometry resp = null; |
... | ... | |
259 | 258 |
|
260 | 259 |
if (meta == null) { |
261 | 260 |
// error |
262 |
logger.error(Utils.time() |
|
263 |
+ "No se pudo obtener metadatos de archivo SHP: " |
|
261 |
logger.error("No se pudo obtener metadatos de archivo SHP: " |
|
264 | 262 |
+ fileShp.getName()); |
265 | 263 |
type = SHP.SHPT_NULL; |
266 | 264 |
extent = new Rectangle2D.Double(0, 0, 1, 1); |
... | ... | |
339 | 337 |
initialize(); |
340 | 338 |
} |
341 | 339 |
|
342 |
/** |
|
343 |
* Initializes the driver with the given table definition. Currently unused. |
|
344 |
* |
|
345 |
* @param layerDef |
|
346 |
* the table definitiion to be used |
|
347 |
*/ |
|
348 |
public void initialize(ITableDefinition layerDef) { |
|
349 |
} |
|
350 | 340 |
|
341 |
|
|
351 | 342 |
/** |
352 | 343 |
* @return Whether the driver is writable. Currently unused. |
353 | 344 |
* |
... | ... | |
422 | 413 |
return resp; |
423 | 414 |
} |
424 | 415 |
|
425 |
private IGeometry fastGeometryToFMapGeometry(FMapFastGeometry fg, int type)
|
|
416 |
private Geometry fastGeometryToFMapGeometry(FMapFastGeometry fg, int type) |
|
426 | 417 |
throws Exception { |
427 | 418 |
|
428 | 419 |
if (fg == null) |
429 | 420 |
return null; |
430 |
IGeometry ig = null;
|
|
421 |
Geometry ig = null; |
|
431 | 422 |
|
432 | 423 |
GeneralPathX elShape; |
433 | 424 |
int numParts, i, v; |
... | ... | |
437 | 428 |
double[] pointx; |
438 | 429 |
double[] pointy; |
439 | 430 |
double[] pointz; |
440 |
|
|
431 |
GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory(); |
|
441 | 432 |
switch (type) { |
442 | 433 |
|
443 | 434 |
case SHP.SHPT_POLYGON: |
... | ... | |
454 | 445 |
} |
455 | 446 |
} |
456 | 447 |
zc = getDoubleArray(zcoords); |
457 |
ig = ShapeFactory.createPolygon2D(elShape);
|
|
448 |
ig = gFactory.createPolygon2D(elShape);
|
|
458 | 449 |
break; |
459 | 450 |
|
460 | 451 |
// ------------------------------------------------------------- |
... | ... | |
473 | 464 |
elShape.lineTo(part[2 * v], part[2 * v + 1]); |
474 | 465 |
} |
475 | 466 |
} |
476 |
ig = ShapeFactory.createPolyline2D(elShape);
|
|
467 |
ig = gFactory.createPolyline2D(elShape);
|
|
477 | 468 |
break; |
478 | 469 |
|
479 | 470 |
// ------------------------------------------------------------- |
... | ... | |
496 | 487 |
} |
497 | 488 |
} |
498 | 489 |
zc = getDoubleArray(zcoords); |
499 |
ig = ShapeFactory.createPolyline3D(elShape, zc);
|
|
490 |
ig = gFactory.createPolyline3D(elShape, zc);
|
|
500 | 491 |
break; |
501 | 492 |
|
502 | 493 |
// ------------------------------------------------------------- |
... | ... | |
519 | 510 |
} |
520 | 511 |
} |
521 | 512 |
zc = getDoubleArray(zcoords); |
522 |
ig = ShapeFactory.createPolygon3D(elShape, zc);
|
|
513 |
ig = gFactory.createPolygon3D(elShape, zc);
|
|
523 | 514 |
break; |
524 | 515 |
|
525 | 516 |
// ------------------------------------------------------------- |
... | ... | |
527 | 518 |
|
528 | 519 |
case SHP.SHPT_POINT: |
529 | 520 |
part = fg.getPart(0); |
530 |
ig = ShapeFactory.createPoint2D(part[0], part[1]);
|
|
521 |
ig = gFactory.createPoint2D(part[0], part[1]);
|
|
531 | 522 |
break; |
532 | 523 |
|
533 | 524 |
// ------------------------------------------------------------- |
... | ... | |
543 | 534 |
pointx[i] = part[0]; |
544 | 535 |
pointy[i] = part[1]; |
545 | 536 |
} |
546 |
ig = ShapeFactory.createMultipoint2D(pointx, pointy);
|
|
537 |
ig = gFactory.createMultipoint2D(pointx, pointy);
|
|
547 | 538 |
break; |
548 | 539 |
|
549 | 540 |
// ------------------------------------------------------------- |
... | ... | |
552 | 543 |
case SHP.SHPT_POINTZ: |
553 | 544 |
case SHP.SHPT_POINTM: |
554 | 545 |
part = fg.getPart(0); |
555 |
ig = ShapeFactory.createPoint3D(part[0], part[1], part[2]);
|
|
546 |
ig = gFactory.createPoint3D(part[0], part[1], part[2]);
|
|
556 | 547 |
break; |
557 | 548 |
|
558 | 549 |
// ------------------------------------------------------------- |
... | ... | |
571 | 562 |
pointy[i] = part[1]; |
572 | 563 |
pointz[i] = part[2]; |
573 | 564 |
} |
574 |
ig = ShapeFactory.createMultipoint3D(pointx, pointy, pointz);
|
|
565 |
ig = gFactory.createMultipoint3D(pointx, pointy, pointz);
|
|
575 | 566 |
break; |
576 | 567 |
} |
577 | 568 |
|
... | ... | |
587 | 578 |
} |
588 | 579 |
|
589 | 580 |
/** |
581 |
* Returns whether these rectangles intersect (this was necessary because the original |
|
582 |
* metod behaves in a strabge way) |
|
583 |
* |
|
584 |
* @param r_1 |
|
585 |
* @param r_2 |
|
586 |
* @return whether these rectangles intersect |
|
587 |
*/ |
|
588 |
public static boolean rectanglesItersect(Rectangle2D r_1, Rectangle2D r_2) { |
|
589 |
|
|
590 |
if ((r_1 == null) || (r_2 == null)) |
|
591 |
return false; |
|
592 |
if (r_1.getMinX() >= r_2.getMaxX()) |
|
593 |
return false; |
|
594 |
if (r_2.getMinX() >= r_1.getMaxX()) |
|
595 |
return false; |
|
596 |
if (r_1.getMinY() >= r_2.getMaxY()) |
|
597 |
return false; |
|
598 |
if (r_2.getMinY() >= r_1.getMaxY()) |
|
599 |
return false; |
|
600 |
return true; |
|
601 |
} |
|
602 |
|
|
603 |
/** |
|
590 | 604 |
* Gets the indices of the geometries intersecting the given rectangle |
591 | 605 |
* |
592 | 606 |
* @param rect |
... | ... | |
601 | 615 |
for (int i = 0; i < numReg; i++) { |
602 | 616 |
Integer ind_obj = new Integer(i); |
603 | 617 |
Rectangle2D item_bb = (Rectangle2D) shapesBoxes.get(ind_obj); |
604 |
if (Utils.rectanglesItersect(item_bb, rect)) {
|
|
605 |
IGeometry ig = getShape(i);
|
|
606 |
if (ig.getGeometryType() == FShape.POINT || ig.intersects(rect)) {
|
|
618 |
if (rectanglesItersect(item_bb, rect)) { |
|
619 |
Geometry ig = getShape(i); |
|
620 |
if (ig.getType() == FShape.POINT || ig.intersects(rect)) { |
|
607 | 621 |
_resp.add(new Integer(i)); |
608 | 622 |
if (_resp.size() == max) { |
609 | 623 |
break; |
Also available in: Unified diff