[mapguide-users] Issues selecting a feature with custom coding
nclayton
nclayton at gmail.com
Thu Jan 10 17:24:34 EST 2008
Thank you for the reply. That link has helped me see something I was unsure
of originally, and i've made a change to my function for it. I'm still
trying to get a firmer understanding of the concepts, but it's gone from
being clear as tar to clear as mud (so it's an improvement).
function MgBase64_encode($value){
$key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
$dhv = dechex($value);
$grp = (strlen($dhv) / 2);
$arr = array();
for($i=0;$i<$grp;$i++){
$arr[$i] = substr($dhv,($i * 2),2);
}
$arr = array_reverse($arr);
$bvl = decbin(hexdec(join("",$arr)));
// $bvl should represent the first 3 bytes in as a 24 bit
buffer
if(strlen($bvl) > 24){ $bvl = substr($bvl,0,24); }
$p = "";
// Added this...according to the wiki, if there is 1 octet
remaining, append "=="
// and "=" if there are 2 octets remaining.
if((strlen($bvl) / 6) < 3){ $p = "=="; }
else{ $p = "="; }
$chk = (strlen($bvl) % 6);
if($chk > 0){ $bvl = str_pad($bvl,(strlen($bvl) + (6 - $chk)),'0'); }
$grp = (strlen($bvl) / 6);
$arr = array();
for($i=0;$i<$grp;$i++){
$arr[$i] = substr($key,bindec(substr($bvl,($i * 6),6)),1);
}
return str_pad(join("",$arr),6,'A') . $p;
}
A couple of things in the article weren't clear to me...such as:
An octet is a group of 8 bits. (I understand this)
"The process is repeated on the remaining data until fewer than four octets
remain"...if it's a 24 bit buffer, it's always fewer than 4 octets correct?
Since 24 / 8 = 3?
Or is the article using the term octet to describe the 6 bit chunks used to
decide the index for the key string?
So far this code is working and i'm able to select my parcel feature, but
I'm afraid it may fall through at some point. Any clearity on the subject
will be much appreciated
Nick
The wiki article mentions that
Kenneth, GEOGRAF A/S wrote:
>
> There is a simple algorithm here:
> http://en.wikipedia.org/wiki/Base64
>
> My PHP is a bit too rusty to comment on the correctness of your code.
>
> Basically Base64 works, by encoding each 6 bits into a character.
> That means it produces 4 bytes per 3 input bytes, and always pads up
> with =, to produce a string of a length divisible by 4.
> I _think_ the strings ID columns are encoded as an UTF-8 byte array into
> Base64.
>
> Regards, Kenneth, GEOGRAF A/S
>
>
>
> nclayton skrev:
>> I have created this function in php which gives me the correct value for
>> 33181 ("nYEAAA==") but I would like for another pair of eyes (or 20) to
>> see
>> if this is solid and if it can be simplified.
>>
>> function MgBase64_encode($value){
>>
>> $key="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
>> $dhv = dechex($value);
>> $grp = (strlen($dhv) / 2);
>> $arr = array();
>> for($i=0;$i<$grp;$i++){
>> $arr[$i] = substr($dhv,($i * 2),2);
>> }
>> $arr = array_reverse($arr);
>> $bvl = decbin(hexdec(join("",$arr)));
>> $chk = (strlen($bvl) % 6);
>> if($chk > 0){ $bvl = str_pad($bvl,(strlen($bvl) + (6 - $chk)),'0'); }
>> $grp = (strlen($bvl) / 6);
>> $arr = array();
>> for($i=0;$i<$grp;$i++){
>> $arr[$i] = substr($key,bindec(substr($bvl,($i * 6),6)),1);
>> }
>>
>> return str_pad(join("",$arr),6,'A') . "==";
>> }
>>
>>
>> Nick
>>
>>
>>
>>
>> nclayton wrote:
>>
>>> Thank you for the reply and the link. I'd actually read that post, but
>>> it
>>> gave me a bit of a headache trying to reverse the process...I'm rather
>>> new
>>> to this mode of thinking (i avoided it as long as i could).
>>>
>>> As far as the parcel number value is concerned, it needs to be a string
>>> because they are different for each county that we deal with and are
>>> typically 14-22 alphanumeric characters in length, such as
>>> '1-023B-001.000'
>>>
>>> Nick
>>>
>>>
>>> JasonBirch wrote:
>>>
>>>> More details on this here:
>>>>
>>>> http://tinyurl.com/2rrq3e
>>>>
>>>> I'm definitely a bit rusty on this stuff, but in your initial problem
>>>> are you sure you want to be using a string value for the parcel id?
>>>>
>>>> Jason
>>>>
>>>> -----Original Message-----
>>>> From: nclayton
>>>> Subject: Re: [mapguide-users] Issues selecting a feature with custom
>>>> coding
>>>>
>>>> Here are the results of both the mgos base64 value and the php
>>>> base64_encode
>>>> value:
>>>>
>>>> Actual FeatId: 33181
>>>> MGOS Value: nYEAAA==
>>>> base64_encode Value: MzMxODE=
>>>>
>>>> I found code for writing a base64 function in javascript, and it gives
>>>> the same result as the php function.
>>>> _______________________________________________
>>>> mapguide-users mailing list
>>>> mapguide-users at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>>
>>>>
>>>>
>>>
>>
>>
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>
--
View this message in context: http://www.nabble.com/Issues-selecting-a-feature-with-custom-coding-tp14694817s16610p14745433.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list