public static function getGeometryType($conn, $tablename, $fieldname) { $geo_type = ''; $sql = "select distinct(ST_GeometryType(" . $fieldname . ")) as type from " . $tablename . " where " . $fieldname . " is not null"; $stmt = $conn->fetchAll($sql); if ($stmt) { foreach ($stmt as $type) { $geo_type = DefaultMethods::getGeoType($geo_type, $type); } } return $geo_type; }
/** * Constructor */ public function __construct() { $this->id = DefaultMethods::gen_uuid(); }
private function processEachSpatialFile($files, $filetype, $spatialfilename, $sheetname, $bexcel = false) { $dbparams = DefaultMethods::getDatabaseParams($this); $em = $this->getDoctrine()->getManager(); $runResult = null; $entity_classname = $em->getClassMetadata($this->getParameter('map2u.core.spatialfile.class'))->getName(); $spatialfile = $em->getRepository($entity_classname)->findOneBy(array("userId" => $this->getUser()->getId(), "fileName" => $spatialfilename, 'sheetName' => $sheetname)); if ($spatialfile === null) { $spatialfile = new $entity_classname(); $spatialfile->setUserId($this->getUser()->getId()); $spatialfile->setUser($this->getUser()); } if (count($spatialfile->getCategories()) > 0) { foreach ($spatialfile->getCategories() as $category) { $spatialfile->removeCategory($category); } } if ($this->params['categories'] !== null) { $spatialfile->addCategory($this->params['categories']); } if (count($spatialfile->getTags()) > 0) { foreach ($spatialfile->getTags() as $tag) { $spatialfile->removeTag($tag); } } if ($this->params['tags'] !== null) { $spatialfile->addTag($this->params['tags']); } $spatialfile->setFileType($filetype); $spatialfile->setSupportType($this->params['spatial_typeid']); $spatialfile->setSessionId($this->params['sessionid']); $spatialfile->setFileName($spatialfilename); $spatialfile->setSheetName($sheetname); $em->persist($spatialfile); $em->flush(); $id = str_replace('-', '_', $spatialfile->getId()); $dir = $this->get('kernel')->getRootDir() . '/../Data/uploads/spatialfiles/spatial_' . str_replace('-', '_', $id); if (file_exists($dir) === false) { shell_exec('mkdir -p ' . $dir); } $filenames = SpatialFileMethods::saveSpatialFile($dir, $files, $bexcel); if (count($filenames) > 0 && ($filetype === 'shapefile' || $filetype === 'mapinfo' || $filetype === 'kml')) { $runResult = SpatialFileMethods::ogr2ogrToDatabase($dir, $spatialfile, $dbparams); if ($runResult === null) { DefaultMethods::setDatabaseTableUUID($this, "spatial_" . $id); $columns = DefaultMethods::getTableColumns($this, "spatial_" . $id); $geo_type = DefaultMethods::getGeometryType($this->get("database_connection"), "spatial_" . $id, 'the_geom'); $spatialfile->setFieldList(serialize($columns)); SpatialFileMethods::ogr2ogrDatabaseToGeoJSON($dir, $spatialfile, $dbparams, $geo_type); $em->persist($spatialfile); } else { $em->remove($spatialfile); } } else { $runResult = $this->processTextfileDataToDatabase($dir, $spatialfile, $sheetname, $bexcel); if ($runResult === null) { DefaultMethods::setDatabaseTableUUID($this, "spatial_" . $id); $columns = DefaultMethods::getTableColumns($this, "spatial_" . $id); $spatialfile->setFieldList(serialize($columns)); $geo_type = DefaultMethods::getGeometryType($this->get("database_connection"), "spatial_" . $id, 'the_geom'); SpatialFileMethods::ogr2ogrDatabaseToGeoJSON($dir, $spatialfile, $dbparams, $geo_type); $em->persist($spatialfile); } else { $em->remove($spatialfile); } } $em->flush(); return [$runResult, $spatialfile]; }