Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-从';点';形状_Php_Google Maps_Kml_Shapefile - Fatal编程技术网

PHP-从';点';形状

PHP-从';点';形状,php,google-maps,kml,shapefile,Php,Google Maps,Kml,Shapefile,我正在使用库生成KML并将数据显示到google地图上,但当它指向“点”形状时,它不起作用,也不会为相同的对象生成KML。 下面是多边形形状的代码片段,帮助我创建点形状 //this shape data i'm fetching from shapefile library. $shp_data = $record->getShpData(); if (isset($shp_data['parts'])) { $counter1 = 0; if ($shp_dat

我正在使用库生成KML并将数据显示到google地图上,但当它指向“点”形状时,它不起作用,也不会为相同的对象生成KML。 下面是多边形形状的代码片段,帮助我创建点形状

//this shape data i'm fetching from shapefile library.        
$shp_data = $record->getShpData();
if (isset($shp_data['parts'])) {
  $counter1 = 0;
  if ($shp_data['numparts']) {
    $polygon_array['polygon']['status'] = 'multi-polygon';
  } else {
    $polygon_array['polygon']['status'] = 'single-polygon';
  }

  $polygon_array['polygon']['total_polygon'] = $shp_data['numparts'];

  foreach ($shp_data['parts'] as $polygon) {
    foreach ($polygon as $points) {
      $counter = 0;
      $polygon_string = '';

      while ($counter < count($points)) {
        if ($counter == 0) {
          $polygon_string = $points[count($points) - 1]['x'] . ',';
          $polygon_string .= $points[$counter]['y'] . ' ' . $points[$counter]['x'] . ',';
        } else if ($counter == count($points) - 1) {
          $polygon_string .= $points[$counter]['y'];
        } else {
          $polygon_string .= $points[$counter]['y'] . ' ' . $points[$counter]['x'] . ',';
        }
        $counter = $counter + 1;
      }
      $polygon_single[$counter1] = $polygon_string;
      $polygon_array['polygon']['view'] = $polygon_single;
      $counter1 = $counter1 + 1;
    }
  }
  $arr[$i] = $polygon_array;
  $i++;
} 
//我正在从shapefile库获取此形状数据。
$shp_data=$record->getShpData();
如果(isset($shp_数据['parts'])){
$1=0;
如果($shp_数据['numparts'])){
$polygon_数组['polygon']['status']='multi polygon';
}否则{
$polygon_数组['polygon']['status']='singlepolygon';
}
$polygon_数组['polygon']['total_polygon']=$shp_数据['numparts'];
foreach($shp_数据['parts']作为$polygon){
foreach($多边形作为$点){
$counter=0;
$polygon_string='';
而($计数器<计数($点数)){
如果($counter==0){
$polygon_string=$points[count($points)-1]['x'.',';
$polygon_string.=$points[$counter]['y'].'。$points[$counter]['x'.',';
}else if($counter==计数($points)-1){
$polygon_string.=$points[$counter]['y'];
}否则{
$polygon_string.=$points[$counter]['y'].'。$points[$counter]['x'.',';
}
$counter=$counter+1;
}
$polygon\u single[$counter1]=$polygon\u字符串;
$polygon_数组['polygon']['view']=$polygon_single;
$counter1=$counter1+1;
}
}
$arr[$i]=$polygon_数组;
$i++;
} 

对于点几何图形,此条件将失败:

if (isset($shp_data['parts'])) {
不幸的是,您正在使用的ShapeFile PHP库似乎没有正确的方法来标识几何体类型

作为一种解决方法,如果上述检查失败,则可以检查几何体是否具有
x
y
坐标,如下所示:

if (isset($shp_data['parts'])) {
  // probably a polygon
  // ... your code here ...
} elseif(isset($shp_data['y']) && isset($shp_data['x'])) {
  // probably a point
  $point = [];
  $point["coordinates"] = $shp_data['y'] .' '. $shp_data['x'];
  $arr[$i]['point'] = $point;
}
这将生成一个如下所示的数组:

  [0]=>
  array(1) {
    ["point"]=>
    array(1) {
      ["coordinates"]=>
      string(34) "0.75712656784493 -0.99201824401368"
    }
  }

你知道有其他的图书馆吗?@Rorschach没有,对不起