1

ポリゴンの座標に基づいて DXF ファイルを書き込む PHP スクリプトを見つけました。IT は、次のコード (ポリゴン用) を使用してテスト ファイルを処理します。

$d->append(new DxfPolyLine(array('points'=>array(array(1, 1),
                                        array(20, 10), 
                                        array(20, 20), 
                                        array(1, 15)),
                            'lineType'=>'DASHED',
//                          'layer' => 'DXFWRITER',
                            'flag' => 0
                            //'width' => 1,
                            //'color'=>1
                            )
));

DXF ファイルの結果は次のようになります。

VERTEX
8
0
6
DASHED
10
20.000
20
20.000
0
VERTEX
8
0
6
DASHED
10
1.000
20
15.000
0

ポリライン内に多くの頂点があります。今、私は自分の座標を挿入しようとしています。座標はありますが、その配列に配列を書き込むにはどうすればよいですか? 私はこれを持っています:$g=array_merge($g,array(array($coord[$z]*3.527785, $coord[$z+1]*3.527785))); このコードで結果は次のとおりです:

    Array ( [0] => Array ( [0] => -133.92170714209 [1] => -41.834100838885 ) [1] => Array ( [0] => -135.19600658422 [1] => -44.558002415365 ) [2] => Array ( [0] => -173.40700872797 [1] => -25.465001344078 ) [3] => Array ( [0] => -211.44500829533 [1] => -6.4740001788315 ) [4] => Array ( [0] => -209.93490817601 [1] => -3.255100166471 ) [5] => 
Array ( [0] => -190.0770099388 [1] => -13.202000524885 ) [6] => Array ( [0] => -171.92300716209 [1] => -22.296000898041 ) [7] => Array ( [0] => -172.13500940166 [1] => -22.749000947663 ) [8] => Array ( [0] => -171.12900859213 [1] => -23.251001225378 ) [9] => Array ( [0] => -152.49300807866 [1] => -32.559001622754 ) [10] => Array ( [0] => -133.92170714209 [1] => -41.834100838885 ) ) 

ここまでは順調ですね。例の形式を尊重します。しかし、DXF ファイルでは (配列番号から) 1 だけを書き込みます。コードを変更すると

$d->append(new DxfPolyLine(array('points'=>array($g[3]),

array[3] を使用 - 座標を DXF ファイルに書き込みます。配列からすべての配列を読み取るようにphpを作成する方法はありますか? foreach で試してみましたが、うまくいきません。PHP は ) を閉じないとエラーになります。ソースコードはこちら: https://github.com/digitalfotografen/DXFwriter
$g[3] を使用すると、DXF ファイルに配列 [3] からの座標があります。

VERTEX
8
0
6
CONTINUOUS
10
-211.445
20
-6.474
0

$g simple を置くと、次のようになります。

VERTEX
8
0
6
CONTINUOUS
10
1.000
20
1.000
30
1.000
40
1.000
50
1.000
60
1.000
70
1.000
4

2 に答える 2

0

Your formatting's a bit screwy, but looking at the dumped array-data I see a single array who's values are arrays, that have 2 float values each. Note that Array[0] and Array[10] have the same values which may or may not be a problem for the lib.

Also, what's with the asterisks in the $d->append... logic?

Is there a way to make php to read all arrays from an array?

Yes, but PHP will impose some restrictions depending on the nature of the keys and values. See http://php.net/manual/en/language.types.array.php for more specific info as to how PHP treats arrays.

I've tried with foreach but it doesn't work. PHP gives an error for not closing the ).

Can you post the failing code please? What you describe is simply a formatting / syntax error and nothing to do with the data itself.

于 2016-02-21T20:51:08.767 に答える